PDA

View Full Version : Filters with msoFileDialogSaveAs Dialog Box



ftm
01-28-2010, 02:14 AM
I have a need to prompt the user to save their document as soon as it opens. They are provided with a default path but they should type in the filename and click the Save button on the msoFileDialogSaveAs dialog box. My original code is below:

With Application.FileDialog(msoFileDialogSaveAs)
.InitialFileName = "\\Servername\Foldername\"
.Execute
End With
This works OK but the problem is that because the Word document contains a macro it will not allow the user to save the file as the default .docx file type. The workaround is that the user can change the file type in the dropdownlist on the msoFileDialogSaveAs box. However I would much prefer to automate this for them so that the dialog box shows the .docm file type as default.

I have tried to control the filters available to the user but I cannot seem to get the code below to work. The error message when running reports that the method/property is unsupported. However the code compiles and Intellisense offers me the methods I want to use for the msoFileDialogSaveAs object.

With Application.FileDialog(msoFileDialogSaveAs)
.InitialFileName = "\\Servername\Foldername\"
.Title = "Please choose the location to save your experiment write-up"
.Filters.Clear
.Filters.Add "Word Macro-Enabled Document (*.docm)", "*.docm"
.FilterIndex = 0
.Execute
End With
If anybody can help I would be grateful. I just want to offer the msoFileDialogSaveAs dialog box to the user with the .docm file type as default.

lucas
01-28-2010, 09:27 AM
I'm wondering why you are not using a template.

The code to prompt for save can be in the document new procedure and when they save it the code will not be in the clone of the template.

That should allow you to save it the way you want it. I don't have 2007 so I can't verify this but it is the way word works in previous versions.

ftm
02-02-2010, 11:09 AM
I'm wondering why you are not using a template.

The code to prompt for save can be in the document new procedure and when they save it the code will not be in the clone of the template.

That should allow you to save it the way you want it. I don't have 2007 so I can't verify this but it is the way word works in previous versions.

Hi Lucas

Thanks for replying. I'm not sure if I can use a template. There is a macro in the Word document stored on a server. This is called from a web page and the document loads on the user's machine, but then runs the macro with a parameter passed from the web page. The macro does what it has to do with a database connection and the last line of the macro calls my little proc above to force the user to save their document to the appropriate place. This is done because Autosave was kicking in on some machines and attempting to save back to the master read-only server copy of the document.

Is there anything obvious I've done wrong with the filters in the msoFileDialogSaveAs dialog box. The user can get around this by selecting the file type of .docm but I'd much rather it was set for them so they don't have to worry about changing file type.

Many thanks in advance for any help.

lucas
02-02-2010, 01:15 PM
Try something along these lines:

Dim aDialog As Dialog
Dim Maybe As String
Dim CurrentSaveFolder As String

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

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

' change the FileOpen folder
' use YOUR folder!!!!!
' ChangeFileOpenDirectory "F:\Temp\Test"

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

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

ftm
02-09-2010, 06:02 AM
If anybody has a similar problem, I managed to solve this by creating a Digital Certificate and importing into the users' machines so that this particular doc containing a macro was accepted if the client machines were set to the 'Accept with Certificate' Trust Center setting.

fumei
02-09-2010, 10:26 AM
"I managed to solve this by creating a Digital Certificate and importing into the users' machines"

Please describe how you did this.