Save Command Button Help!

E

EnGo

I am trying to create a command button that is attached to a macro tha
will allow the user to save the worksheet that prompts the user for
specified file name. Or automatically save the worksheet as a fiel
name title. Currently this is the code I have:
Private Sub SaveButton_Click()

ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\MYoung\Desktop\h&h VALVE\"
Range("Company:"), _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
End Sub

or
Sub Save()
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\MYoung\Desktop\h&h VALVE\"
Range("Company:"), _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
End Sub

the top is code I just applied to the command button to try it, and th
bottom is the code for the macro.

I would appreciate any help I can get on this. Thank you in advance
 
L

Les

You want to determine the filename prior to saving the workbook.
Use the GetSaveAsFilename method.

For example:

Dim defaultName As String
Dim myFileName As String


defaultName = Range("Company")

myFileName = Application _
.GetSaveAsFilename(defaultName, "Excel Workbook (*.xls), *.xls", , _
"Save a new version of the workbook")

If myFileName <> "False" Then
ActiveWorkbook.SaveAs Filename:=myFileName
End If

I would suggest that you drop the default directory and let the user decide.
I do not think that you can set it easily in VBA.

Hope this helps steer you the right way.
 

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