Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get the SaveAsDialog to show the path I have in strDocPath?

Status
Not open for further replies.

YACHTIE

Technical User
Feb 17, 2004
77
CA
Hi all,
Have limited VBA capability and have gleaned the following code from various sources and it sorta works.
I am trying to have the fileSaveAs dialog forced to save to the users desktop, iow the default path showing up should point to the user's desktop instead of the last foldr used to open the document in question.

The doc is a Word doc with tables and formfield, protected and when opened the Document_Open event calls this macro with an "If" statement on Filename and I want to force a SaveAs upon opening the document but now the user has to navigate to a location of his choice or save in the default path's location which is not good.

How do I get the SaveAsDialog to show the path I have in strDocPath?
Also how can I disable the "Cancel" button on the SaveAs dialog?

Code follows:
Code:
Sub ShowSaveAsDialog()
Dim objWSH
Dim uName As String 'holds the users login name
Set objWSH = CreateObject("WScript.Network")
uName = objWSH.UserName 'get the user's name
strDocPath = "C:\Documents and Settings\" & uName & "\Desktop\"  'to make path
strDocName = "MyNewCN.doc"
    Dim dlgSaveAs As Dialog
    Set dlgSaveAs = Dialogs(wdDialogFileSaveAs)
    dlgSaveAs.Show             'Dialog with default NOT specified path
    ActiveDocument.SaveAs FileName:=strDocPath & strDocName 'This saves doc in background
    Set objWSH = Nothing
End Sub
TIA
 
Hi YACHTIE,

If you want to force a SaveAs, don't ask the user to do it, just code it right in there. Use [blue]ActiveDocument.SaveAs YourPathAndName[/blue]

Also, to get UserName you can use [blue]Environ("UserName")[/blue] - no need for the script object,

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
I appreciate your point of view here and I sorta agree however, when I did that the user did not know where it was saved and I prefer to have the user specify the new filename, thus my compromise with the SaveAs diaog prompt.
As I have it now the "lazy user" just presses the Cancel button essentially defeating my solution and keeping the original form occupied.
Therefore my ideal solution would be to disable the "cancel" button in this instance.
 

Why not issue a message saying "Saved As (whatever)".

If you really want to have the User interact with a Dialog you're going to find it difficult (if not impossible) to control the builtin dialog the way you want and it would be better to set up your own userform as a front end to the process.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
Have worked it with some help as follows and this works for me:
Code:
  With Dialogs(wdDialogFileSaveAs)
    .Name = strDocPath
    .Show
    While .Show = SAVE_PRESSED
    Wend
  End With

Inserted this in the macro and it really does not let the user pass the cancel option and forces himto do a save instead, maybe not ideal but its an acceptable workaround.

Thanks for all the suggestions,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top