+ Reply to Thread
Results 1 to 2 of 2

Save Command Button Help!

  1. #1
    Registered User
    Join Date
    07-27-2006
    Posts
    1

    Save Command Button Help!

    I am trying to create a command button that is attached to a macro that will allow the user to save the worksheet that prompts the user for a specified file name. Or automatically save the worksheet as a field 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 the bottom is the code for the macro.

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

  2. #2
    Les
    Guest

    RE: Save Command Button Help!

    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.
    --
    Les Torchia-Wells


    "EnGo" wrote:

    >
    > I am trying to create a command button that is attached to a macro that
    > will allow the user to save the worksheet that prompts the user for a
    > specified file name. Or automatically save the worksheet as a field
    > 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 the
    > bottom is the code for the macro.
    >
    > I would appreciate any help I can get on this. Thank you in advance.
    >
    >
    > --
    > EnGo
    > ------------------------------------------------------------------------
    > EnGo's Profile: http://www.excelforum.com/member.php...o&userid=36863
    > View this thread: http://www.excelforum.com/showthread...hreadid=565763
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1