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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save my document

Status
Not open for further replies.

wmbb

Technical User
Jul 17, 2005
320
NL
Why doesn't this code save my document as "planning 2011.xlsm" when clicked on save?
This code doesn't save anything !

Code:
Set fd = Application.FileDialog(msoFileDialogSaveAs)
With fd
          .AllowMultiSelect = False
          .InitialView = msoFileDialogViewDetails
          .Title = "Choose file location..."
          .InitialFileName = "planning 2011.xlsm"
          .Show
End With
 
Hi wmmb,
You need to execute the save and, since you want to save in xlsm format, you also need to set the filterindex (otherwise an xlsx format will be offered)
Code:
With Application.FileDialog(msoFileDialogSaveAs)
  .FilterIndex = 2
  .AllowMultiSelect = False
  .InitialView = msoFileDialogViewDetails
  .Title = "Choose file location..."
  .InitialFileName = "planning 2011.xlsm"
  If .Show <> -1 Then .Execute
End With

Cheers
Paul Edstein
[MS MVP - Word]
 
I can't get this code working.

First I think the code should be
Code:
If .Show = -1 Then .Execute
because when I click on save the value equals -1

But in both cases the file doesn't save.

In case .show <> -1 the file doesn't save when clicked on save or cancel
In case .show = -1 the file doesn't save when clicked on cancel and an error appears when clicked on save:
Run-time error '-2147467259 (80004005)'
Method 'Execute' of object 'FileDialog' failed


Any Suggestions ?
 
Additional information...

I figured out the code shows a "File Save" dialog instead of a "Save As" dialog.

Maybe this gives you an idea what goes wrong...
 
Hi wmbb,

Yes, it should have been:
Code:
If .Show = -1 Then .Execute
Other than that, the code works fine for me.

Cheers
Paul Edstein
[MS MVP - Word]
 
Is the dialog for you a "File Save" dialog or a "Save As" dialog ?
Do you recognize the error ?
Could this be a MS Office setting ?

Searching the internet they are talking about an error caused by the wrong use of the active document and ThisDocument. Do you what they mean by that ?
 
Another strange phenomena, in MS WORD the code works without any problem ??!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top