Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-22-2013, 08:37 PM
WyRm WyRm is offline Adding a Save button into a document Windows 7 64bit Adding a Save button into a document Office 2010 64bit
Novice
Adding a Save button into a document
 
Join Date: Mar 2013
Posts: 7
WyRm is on a distinguished road
Default Adding a Save button into a document

So i was looking through the forum and a total newbie to advance stuff with office. I found this but not sure what to do to edit it for my needs.


Code:
Private Sub Document_New()
Dim StrName As String, StrDefPath As String, StrTmpPath As String
StrName = Environ("UserName") & Format(Now, "YYYYMMDD")
StrTmpPath = "Filepath for documents based on this template"
StrDefPath = Options.DefaultFilePath(wdDocumentsPath)
Options.DefaultFilePath(wdDocumentsPath) = StrTmpPath
With Application.Dialogs(wdDialogFileSaveAs)
  .Name = StrName
  .Show
End With
Options.DefaultFilePath(wdDocumentsPath) = StrDefPath
End Sub
I want to make it so it uses a particular line and the date as the saving format.

ex. One of the lines in the form is Residence:

So would like when they press the save button it would save the file as

Residence Date.doc

Can this be down and for the path's do I put in the actual path like c:\user\temp\Documents\forms

Thanks in advance

Last edited by macropod; 03-22-2013 at 10:12 PM. Reason: Added code tags & formatting
Reply With Quote
  #2  
Old 03-22-2013, 10:22 PM
macropod's Avatar
macropod macropod is offline Adding a Save button into a document Windows 7 64bit Adding a Save button into a document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hy WyRm,

The code you posted is for automatically saving a new document with the user's name & date, even before they start working on it.

What you're describing, though, is a process that intercepts the File|Save process to suggest a filname based on some content in the document, plus the date. This too could be done, but you would need to ensure the data for the filename are always in the same location and do not contain characters that aren't valid for a filename. Things one can't rely on include content being in, say, the 3rd paragraph, as that could get messed up by it being deleted or paragraphs being inserted/deleted ahead of it. You could, however, refer to a non-deletable content control via its title. Even then, you'd need error handling for what to do if the 'name' is empty when the user tries to save the file.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-22-2013, 10:54 PM
WyRm WyRm is offline Adding a Save button into a document Windows 7 64bit Adding a Save button into a document Office 2010 64bit
Novice
Adding a Save button into a document
 
Join Date: Mar 2013
Posts: 7
WyRm is on a distinguished road
Default

Made all stuff they enter non-deletable and also made the Residence part a drop down with the choices they have.
Reply With Quote
  #4  
Old 03-22-2013, 11:07 PM
macropod's Avatar
macropod macropod is offline Adding a Save button into a document Windows 7 64bit Adding a Save button into a document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by WyRm View Post
Made all stuff they enter non-deletable and also made the Residence part a drop down with the choices they have.
That's nice, but unless you say what kind on dropdown you're using (eg formfield, content control) and how the code might locate it, we're not going to make much progress.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 03-22-2013, 11:11 PM
WyRm WyRm is offline Adding a Save button into a document Windows 7 64bit Adding a Save button into a document Office 2010 64bit
Novice
Adding a Save button into a document
 
Join Date: Mar 2013
Posts: 7
WyRm is on a distinguished road
Default

This is all new so I do apologize. I'm a little lost on what you are asking. I have attached the file. Am not asking some one to do it for me but to help me figure out this step.

Thanks
Attached Files
File Type: docx Incident Report.docx (24.9 KB, 8 views)
Reply With Quote
  #6  
Old 03-22-2013, 11:43 PM
macropod's Avatar
macropod macropod is offline Adding a Save button into a document Windows 7 64bit Adding a Save button into a document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

OK, you're using content controls. But. Since you document has access to their properties locked via a password, I can't refer to it by name ...

That said, one can still refer to it as the first content control in the document.

If you add the following code to your incident report template's 'ThisDocument' code module, you should be able to get the result you're after. The code intercepts both the File|Save and File|SaveAs processes. By default, the code attempts to save the file to the folder you nominated but, if it doesn't exist, a folder browser pops up so the user can select another one (or create the missing one).
Code:
Sub FileSaveAs()
Dim StrPath As String, StrName As String
StrPath = "C:\" & Environ("Username") & "\Temp\Documents\Forms\"
StrName = ActiveDocument.ContentControls(1).Range.Text
If StrName Like "Choose*" Then
  MsgBox "Error: Residence incomplete", vbCritical
  Exit Sub
End If
If Dir(StrPath) = "" Then
  StrPath = GetFolder
  If StrPath = "" Then
    MsgBox "No Save Path Available", vbCritical
    Exit Sub
  End If
  StrPath = StrPath & "\"
End If
With Application.Dialogs(wdDialogFileSaveAs)
  .Name = StrPath & StrName & "_" & Format(Now, "YYYYMMDD")
  .Show
End With
End Sub
 
Sub FileSave()
With ActiveDocument
  If Not Right(Left(.FullName, InStrRev(.FullName, ".") - 1), 8) Like "########" Then
    Call FileSaveAs
    Exit Sub
  End If
  .Save
End With
End Sub
 
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 03-22-2013, 11:56 PM
WyRm WyRm is offline Adding a Save button into a document Windows 7 64bit Adding a Save button into a document Office 2010 64bit
Novice
Adding a Save button into a document
 
Join Date: Mar 2013
Posts: 7
WyRm is on a distinguished road
Default

Thank You very much. Looking at this is making sense more
Reply With Quote
  #8  
Old 03-23-2013, 01:51 AM
WyRm WyRm is offline Adding a Save button into a document Windows 7 64bit Adding a Save button into a document Office 2010 64bit
Novice
Adding a Save button into a document
 
Join Date: Mar 2013
Posts: 7
WyRm is on a distinguished road
Default

All that work and it will not work on a mac
Reply With Quote
  #9  
Old 03-23-2013, 01:59 AM
WyRm WyRm is offline Adding a Save button into a document Windows 7 64bit Adding a Save button into a document Office 2010 64bit
Novice
Adding a Save button into a document
 
Join Date: Mar 2013
Posts: 7
WyRm is on a distinguished road
Default

Guess I should say the template doesn't work on mac
Reply With Quote
  #10  
Old 03-23-2013, 01:59 AM
macropod's Avatar
macropod macropod is offline Adding a Save button into a document Windows 7 64bit Adding a Save button into a document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Macs are different, but your profile indicates Office 2010 on Win 7 ... For one thing, Neither ActiveX controls nor content controls work on Macs.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 03-23-2013, 02:03 AM
WyRm WyRm is offline Adding a Save button into a document Windows 7 64bit Adding a Save button into a document Office 2010 64bit
Novice
Adding a Save button into a document
 
Join Date: Mar 2013
Posts: 7
WyRm is on a distinguished road
Default

It is I have it on PC and Use mac at work. Like I said I am a newbie on advance stuff for office and did not realize it would be a issue to use on mac.
Reply With Quote
  #12  
Old 03-23-2013, 02:21 AM
macropod's Avatar
macropod macropod is offline Adding a Save button into a document Windows 7 64bit Adding a Save button into a document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

That's a bit of a problem then ... there isn't much of the code that is transferable - all content control references would have to be replaced with references to the formfields you replace them with. Another thing that wouldn't transfer is the default save path from your first post. IIRC, Mac filepaths also use ':' or '/' instead of '\' as the separators.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #13  
Old 03-23-2013, 05:10 AM
macropod's Avatar
macropod macropod is offline Adding a Save button into a document Windows 7 64bit Adding a Save button into a document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi WyRm,

If you post a query at: http://answers.microsoft.com/en-us/mac/forum/macword, including the code I've given you, someone there will probably be able to adapt it to the Mac platform.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a Save button into a document Command button - save in temp folder and send email with attachment bigbird69 Word VBA 13 11-18-2012 10:06 PM
Adding a Save button into a document Command Button will not work when document is protected brockjensen Word 1 11-02-2012 06:59 PM
Word ask to save template whenever i save a derived document jorbjo Word 3 10-04-2012 10:52 AM
Adding a Save button into a document Adding email button to Word form leilers Word 5 01-09-2012 03:21 PM
Adding an Email Button to a Word Document maddoktor Word 0 12-01-2011 01:32 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:21 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft