PDA

View Full Version : SmartSave - Default Save As Directory Linked to Text Form Field



bstephens
11-25-2009, 12:45 AM
I am trying to create a "SmartSave" macro whereby a user enters text into a "Text Form Field" and that text is appended to a static network path as the default save directory.

For example, say our standard client letter had a "Text Form Field" and an assistant manually typed a value of "72305.01" (that happens to be the client number) into the "Text Form Field" The macro would suggest a save directory of a static network path "J:\Docs\2009\" appended with "72305.01", so that the default save directory would be "J:\Docs\2009\72305.01".

I started with the following macro I found going through these forums, but I am stuck at the "'what goes here???" comment as to how to add the code which will "append" a static network path with a value from a "Text Form Field".

Also, if I am not using the "Text Form Field" field terminology correctly, I stand humbly corrected.

Sub FileSmartSave()
Dim aDialog As Dialog
Dim FileName As String
Dim CurrentSaveFolder As String

' pick up existing save folder
CurrentSaveFolder = Options _
.DefaultFilePath(Path:=wdDocumentsPath)

' the string for the filename
FileName = "your filename"

' change the FileOpen folder to desired folder
ChangeFileOpenDirectory 'what goes here???

' display FileSaveAs with your filename
' folder is the folder used with ChangeFileOpen
Set aDialog = Application.Dialogs(wdDialogFileSaveAs)
With aDialog
.Name = FileName
.Show
End With

' put the save folder path back
Options.DefaultFilePath(Path:=wdDocumentsPath) = _
CurrentSaveFolder

End Sub
Thanks in advance for any input!

Brian

fumei
11-25-2009, 05:03 AM
1. Bravo for putting things back!!!! Too many people forget this.

2. ChangeFileOpenDirectory 'what goes here???

What goes thereis a string. So, give it a string. If the string is from a text formfield...
ChangeFileOpenDirectory = ActiveDocument.FormFields("name").Result

Be careful though. Your string better be good, with no invalid characters.

Also, are you sure you want to do it this way? If it is essentially one-off (as it seems to be), why not simply save the file to the folder you want?

Also, does this folder already exist, or do you need to create it?