No Success with GetSaveAs

D

D.Parker

How do I get my new workbook filename to save to a given directory? The save
as dialog box pops up with the NewName but unfortunately the file is "not"
saved to the given directory when I click Save.

I have a button on my spreadsheet when initiates the RenameFilenameUponClose
subroutine. Dave kindly gave me advice, upon which I have tried them all but
I still am not getting a new file save to my selected directory.

Is there something obvious I am doing wrong or anything for that matter?
The code is attached.

Sub RenameFilenameUponClose()

Dim SaveName As Variant
Dim fFilter As String
Dim NewName As String

NewName = "P2 LogHistory Shift"
fFilter = "Excel Files (*.xls), *.xls"
SaveName = Application.GetSaveAsFilename _
(NewName, FileFilter:=fFilter, Title:="Save As New P2 Workbook")

If SaveName = True Then
ThisWorkbook.SaveAs Filename:=SaveName, _
FileFormat:=xlWorkbookNormal
Else
Exit Sub
End If

End Sub

Kind regards,

D.Parker
 
R

Rowan

Your macro will never hit the ThisWorkbook.SaveAs statement as SaveName does
not ever evaluate to True. It is either the path and name selected in the
dialog or if the user hits cancel then it is False. Try

Sub RenameFilenameUponClose()

Dim SaveName As Variant
Dim fFilter As String
Dim NewName As String

NewName = "P2 LogHistory Shift"
fFilter = "Excel Files (*.xls), *.xls"
SaveName = Application.GetSaveAsFilename _
(NewName, FileFilter:=fFilter, Title:="Save As New P2 Workbook")

If SaveName = False Then
Exit Sub
Else
ThisWorkbook.SaveAs Filename:=SaveName, _
FileFormat:=xlWorkbookNormal
End If

End Sub

Hope this helps
Rowan
 
D

D.Parker

Wow. Thank you so much. It works!

Thank you for loaning your expertise. You guys/gals are awesome.

D.Parker
 

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