PDA

View Full Version : Set save as dialog title from form field?



irelandmc
07-29-2008, 12:27 PM
Hello all,

This is the goal:
1. User opens a template which is a locked form.
2. On exit of third field, code runs which opens the save as dialog with the default name constructed from the values of the first three fields.
3. User selects location and hits save.

My first thought was to set the value of the title and that the save as would pull that in as the default name, but not so. It still uses the title from the template.

I can force the saveAs, but then the user doesn't get to choose the location, it just puts it in the default location. Not good.

How can force the string into the suggested name without forcing the saveAs? :think:

Can I modify the saveAs call and pass it that string some other way? I mean, the string is RIGHT THERE! :banghead:

Sub SetTitleSave()
'
' SetTitleSave Macro
' Macro created 7/29/2008 by M. Ireland
'
Dim dp As Object
Dim sTitle As String
Set dp = Dialogs(wdDialogFileSummaryInfo)
sTitle = "NPD_" + ActiveDocument.FormFields("Text10").Result + "_" + ActiveDocument.FormFields("Text11").Result + "_rev_" + ActiveDocument.FormFields("Text13").Result
' Set "Title" to a new value.
dp.Title = sTitle
' Set the value without showing the dialog.
dp.Execute

ActiveDocument.SaveAs sTitle


End Sub


Thank you for helping this poor noob.

Mike

macropod
07-29-2008, 11:45 PM
Hi Mike,

Here's one way:
Sub SetTitleSave()
Dim dp As Object
Dim sTitle As String
Set dp = Dialogs(wdDialogFileSummaryInfo)
sTitle = "NPD_" + ActiveDocument.FormFields("Text10").Result + "_" _
+ ActiveDocument.FormFields("Text11").Result + "_rev_" _
+ ActiveDocument.FormFields("Text13").Result
' Set "Title" to a new value.
dp.Title = sTitle
' Set the value without showing the dialog.
dp.Execute
ActiveDocument.SaveAs GetFolder(Title:="Choose the Save Folder", RootFolder:=&H11) & "\" & sTitle
End Sub

Function GetFolder(Optional Title As String, Optional RootFolder As Variant) As String
On Error Resume Next
GetFolder = CreateObject("Shell.Application").BrowseForFolder(0, Title, 0, RootFolder).Items.Item.Path
End Function

irelandmc
07-30-2008, 07:29 AM
Thanks macropod! This accomplishes things nicely.

:beerchug: Cheers!