PDA

View Full Version : Solved: Allow user to choose where to save?



clhare
05-30-2008, 09:36 AM
I need to setup a macro so that a new file will save using a specific filename (that I designate in the macro), but allow the user to select where it will save. I do want to point them in the right direction, though, so I'd like the SaveAs window to start with a particular folder and then the user can go to the correct location from that point.

Is this possible? If so, how would I do that?

Thanks!

fumei
05-30-2008, 01:46 PM
"will save using a specific filename "

Will save? No, it will not. It may save it. Unless YOU do a SaveAs, then your "specific filename" will be inserted as the filename, but there NOTHING to stop the user from changing that name.

So, no..."will save" is not correct.

To answer your question though.

Option Explicit

Sub MaybeThisWay()
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 "C:\ZZZ\"

' 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

End Sub

Of course you do not have to use a string variable for the filename. You can just put it directly into .Name for the dialog.

Set aDialog = Application.Dialogs(wdDialogFileSaveAs)
With aDialog
.Name = any valid string literal, or string variable
.Show
End With

gwkenny
05-30-2008, 01:52 PM
It's really really late, but this is a quick one, so here's what I'd do.

I'd use msoFileDialogOpen from application.filedialog because you don't want to give them the option of changing the filename.

You can set the initial directory with .InitialFilename (believe it or not). Isn't that intuitive!

You can also change the title of the dialog box and other properties as well.

Just open help in the vba editor on the "FileDialog Object" and read through the properties.

You get the value choosen by the user using the SelectedItems property.

Good luck!

fumei
05-30-2008, 01:58 PM
FYI: the .Name property does NOT, repeat not show as a property with IntelliSense. At least with 2002 it doesn't.

So if you make the dialog object, and use a With, putting in a dot (.) will not show Name as a possibility. The displayed list is:

Application
CommandName
DefaultTab
Display
Execute
Parent
Show
Type
Update


....no Name.

However, Name is a valid property...ummmm, otherwise the above code would not work, and it does work.

This is not the only place that IntelliSense does not give all valid properties or methods of an object. In fact, Object itself (e.g. ActiveDocument.InlineShapes(1).OLEFormat.Object) has many other properties after .Object - like Name - but they do not show up.