PDA

View Full Version : Save File Without Showing Window



mferrisi
05-20-2008, 01:16 PM
After making changes to a workbook, the following code brought up a Save As window and allowed the user choose the name and location of the saved document.


Function SaveDoc(wt, Name, IsOpen, TheDate)
If MsgBox("Would you like to save the tagged files for " & Name & "?", vbYesNo) = vbYes Then

With Application.FileDialog(msoFileDialogSaveAs)
.AllowMultiSelect = False
.Show
If .SelectedItems.Count > 0 Then
wbFilename = .SelectedItems(1)
.InitialFileName = wbFilename
.Execute
Else: End If
End With
End Function


As now the program loops though to create multiple documents, I no longer want to have to type the saved name and find the folder. The 'wt' is the path where I want the file to be saved. I attempted to do it liek this:

If MsgBox("Would you like to save the tagged files for " & Name & "?", vbYesNo) = vbYes Then
With Application.FileDialog(msoFileDialogSaveAs)
.AllowMultiSelect = False
wbFilename = Left(wt, Len(wt) - 4) & "_Proc.xls"
.SelectedItems.Application = wbFilename
.InitialFileName = wbFilename
.Execute
End With

But this caused the file to save, but with the original name, ie I save over the original document, and _Proc.xls is not added to the name.

Thank you for your help,

Bob Phillips
05-20-2008, 04:07 PM
I had many difficulties with this code



If MsgBox("Would you like to save the tagged files for " & Name & "?", vbYesNo) = vbYes Then


didn't recognise Name



.SelectedItems.Application = wbFilename


What do you think this line does?

And shouldn't you Show not Execute?

Is wt loaded at any point?

mferrisi
05-21-2008, 06:42 AM
Thank you xld. I think I figured it out. Something like this

Sub SaveCurrentWorkbook()

ThisWorkbook.SaveAs Filename:="test.xls", FileFormat:=xlWorkbookNormal, AddToMru:=True

End Sub