SaveAs dialog

R

R. Choate

Below is a tiny snippet of my code. I'm needing to display the save as dialog and populate the "suggested name" with the text from a
txtbox on my userform. This code almost works but I don't know how to tell the dialog what to put on the Save line. Plz advise.

Dialogs(wdDialogFileSaveAs).Show

ActiveDocument.SaveAs (UserForm1.TxtClientNmbr)

Thanks !!
 
S

Steve Yandl

Try something like this:

thisDocPath = Options.DefaultFilePath(wdDocumentsPath)
strFileName = UserForm1.TxtClientNmbr

With Dialogs(wdDialogFileSaveAs)
.Name = thisDocPath & "\" & strFileName & ".doc"
.Show
End With
 
R

R. Choate

That seems to work fine, thanks. I'm guessing that I will soon be needing to write code to determine what the default path is before
changing to a specified path that everybody will use as the default path that they will only use for the minute or two they are
running my code. Then I'm going to need to change the default path back to whatever it was before they started my code. Can you
suggest how to determine the default path currently set and then change it to "PathX" and finally reset their default path back to
what it was before after running the code you helped me with?

I hope this is making enough sense.

Thanks in advance,
--
RMC,CPA


Try something like this:

thisDocPath = Options.DefaultFilePath(wdDocumentsPath)
strFileName = UserForm1.TxtClientNmbr

With Dialogs(wdDialogFileSaveAs)
.Name = thisDocPath & "\" & strFileName & ".doc"
.Show
End With
 
R

Russ

RMC,
That seems to work fine, thanks. I'm guessing that I will soon be needing to
write code to determine what the default path is before
changing to a specified path that everybody will use as the default path that
they will only use for the minute or two they are
running my code.
You might not need to change the users' defaults since you can save the
output directly to any folder path yourself through the code without user
intervention. Steve is not changing the defaults below. He is just finding
the default path because he assumes that is where you wanted the output
saved. But I added some more comments in case you wanted to change the path
the user sees by default.
Then I'm going to need to change the default path back to
whatever it was before they started my code. Can you
suggest how to determine the default path currently set and then change it to
"PathX" and finally reset their default path back to
what it was before after running the code you helped me with?

That's partly what Steve's code is doing.
See comments below.
I hope this is making enough sense.

Thanks in advance,
--
RMC,CPA


Try something like this:

thisDocPath = Options.DefaultFilePath(wdDocumentsPath)
The current place that Word looks for documents is stored in the variable
'thisDocPath' in the line above. You can reset it to "PathX" with:
Options.DefaultFilePath(wdDocumentsPath) = "PathX"
strFileName = UserForm1.TxtClientNmbr

With Dialogs(wdDialogFileSaveAs)
.Name = thisDocPath & "\" & strFileName & ".doc"
You want to use "PathX" above here instead of 'thisDocPath'
.Show
End With
Before your macro ends you set things back to the way the user wanted at the
start with:
Options.DefaultFilePath(wdDocumentsPath) = thisDocPathAlso see VBA Help for the ChangeFileOpenDirectory Method which temporarily
changes where the 'file open' or 'file save' dialogs open to while the
current session of the Word application is running. When the user starts up
Word again, Word will be set back to its original defaults automatically
again.
 
R

R. Choate

Thank you for your help. I think this will get me over the hump. I appreciate it.
--
RMC,CPA


That seems to work fine, thanks. I'm guessing that I will soon be needing to
write code to determine what the default path is before
changing to a specified path that everybody will use as the default path that
they will only use for the minute or two they are
running my code.
You might not need to change the users' defaults since you can save the
output directly to any folder path yourself through the code without user
intervention. Steve is not changing the defaults below. He is just finding
the default path because he assumes that is where you wanted the output
saved. But I added some more comments in case you wanted to change the path
the user sees by default.
Then I'm going to need to change the default path back to
whatever it was before they started my code. Can you
suggest how to determine the default path currently set and then change it to
"PathX" and finally reset their default path back to
what it was before after running the code you helped me with?

That's partly what Steve's code is doing.
See comments below.
I hope this is making enough sense.

Thanks in advance,
--
RMC,CPA


Try something like this:

thisDocPath = Options.DefaultFilePath(wdDocumentsPath)
The current place that Word looks for documents is stored in the variable
'thisDocPath' in the line above. You can reset it to "PathX" with:
Options.DefaultFilePath(wdDocumentsPath) = "PathX"
strFileName = UserForm1.TxtClientNmbr

With Dialogs(wdDialogFileSaveAs)
.Name = thisDocPath & "\" & strFileName & ".doc"
You want to use "PathX" above here instead of 'thisDocPath'
.Show
End With
Before your macro ends you set things back to the way the user wanted at the
start with:
Options.DefaultFilePath(wdDocumentsPath) = thisDocPathAlso see VBA Help for the ChangeFileOpenDirectory Method which temporarily
changes where the 'file open' or 'file save' dialogs open to while the
current session of the Word application is running. When the user starts up
Word again, Word will be set back to its original defaults automatically
again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top