Providing suggested filename

B

Barb Reinhardt

I want to provide a suggested filename when the user chooses to "SAVEAS". I
get a suggestion and then if I change it, I get another prompt to save as.

Here is my code:



If Not SaveAsUI Then Exit Sub

filesavename = Application.GetSaveAsFilename( _
InitialFileName:=SuggName, _
fileFilter:="Excel Files (*.xls), *.xls")


What am I missing?

Thanks,
Barb Reinhardt
 
D

Doug Glancy

Barb,
If I understand correctly what you wish, there are 3 things you need to do:

Set Cancel to True to cancel Excel's SaveAs dialog, which you are replacing
Do the SaveAs yourself
Validate that they did not clear the name box in the SaveAs Dialog or cancel
it, because if they did, the GetSaveAs will return "False"

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim filesavename As String

If SaveAsUI Then
Cancel = True
filesavename = Application.GetSaveAsFilename( _
InitialFileName:="test3", _
fileFilter:="Excel Files (*.xls), *.xls")
'If they blanked out the name or Canceled, GetSaveAsFilename will return
"False" and you don't want to save
If filesavename <> "False" Then
ThisWorkbook.SaveAs filesavename
End If
Else
Exit Sub
End If
End Sub

hth,

Doug
 
B

Barb Reinhardt

Thanks. That does it.

Doug Glancy said:
Barb,
If I understand correctly what you wish, there are 3 things you need to do:

Set Cancel to True to cancel Excel's SaveAs dialog, which you are replacing
Do the SaveAs yourself
Validate that they did not clear the name box in the SaveAs Dialog or cancel
it, because if they did, the GetSaveAs will return "False"

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim filesavename As String

If SaveAsUI Then
Cancel = True
filesavename = Application.GetSaveAsFilename( _
InitialFileName:="test3", _
fileFilter:="Excel Files (*.xls), *.xls")
'If they blanked out the name or Canceled, GetSaveAsFilename will return
"False" and you don't want to save
If filesavename <> "False" Then
ThisWorkbook.SaveAs filesavename
End If
Else
Exit Sub
End If
End Sub

hth,

Doug
 

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