![]() |
#1
|
|||
|
|||
![]()
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 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 |
#2
|
||||
|
||||
![]()
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] |
#3
|
|||
|
|||
![]()
Made all stuff they enter non-deletable and also made the Residence part a drop down with the choices they have.
|
#4
|
||||
|
||||
![]()
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] |
#5
|
|||
|
|||
![]()
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 |
#6
|
||||
|
||||
![]()
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] |
#7
|
|||
|
|||
![]()
Thank You very much. Looking at this is making sense more
|
#8
|
|||
|
|||
![]()
All that work and it will not work on a mac
![]() |
#9
|
|||
|
|||
![]()
Guess I should say the template doesn't work on mac
|
#10
|
||||
|
||||
![]()
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] |
#11
|
|||
|
|||
![]()
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.
|
#12
|
||||
|
||||
![]()
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] |
#13
|
||||
|
||||
![]()
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] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
bigbird69 | Word VBA | 13 | 11-18-2012 10:06 PM |
![]() |
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 |
![]() |
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 |