+ Reply to Thread
Results 1 to 6 of 6

Using SaveAs & changing the path a file is saved at

Hybrid View

  1. #1
    Registered User
    Join Date
    03-26-2007
    Posts
    92

    Using SaveAs & changing the path a file is saved at

    Hello -

    I have a spreadsheet with a button that saves a worksheet directly to the users C drive. Below is the code that is assigned to the button:

    
    Private Sub CommandButton2_Click()
    ' Saves file in Excel format
        ActiveWorkbook.SaveAs (ThisWorkbook.Sheets("Test").Range("I3").Value & ".xls")
        Application.DisplayAlerts = True
    End Sub
    Range("I3") is a cell that has a string of text with the file path and description of how to save it:

    
    =CONCATENATE("C:\Test Folder\",Test!$E$3)
    E3 is a cell that has another concatenate that results in a name like _2008312_1048. _2008312 is 03/12/2008; _1048 is the time the file was saved.

    I have been asked to change this so it saves to a 'Test Folder' in a user's 'My Documents' folder. Being on a network, the path changes; it's listed as C:\Documents and Settings\[random user name]\My Documents\Test Folder.

    Is there a way for me to acheive this?

    Thank you!

  2. #2
    Registered User
    Join Date
    03-26-2007
    Posts
    92
    If this is not possible, is there a way for me to have the user specify which folder it saves to, but keep the naming format (_20080312_1048) the same?

  3. #3
    Registered User
    Join Date
    03-26-2007
    Posts
    92
    I should also mention that I'm using Excel 2003.

  4. #4
    Registered User
    Join Date
    03-26-2007
    Posts
    92
    I've attempted to use the VBA on this page: http://www.excelforum.com/showthread...ghlight=saveas

    However, I'd like this to happen on the click of a command button and only when that button is clicked, not when the user goes to File > Save, or hits the save button.

    Any suggestions for adaptation?

  5. #5
    Registered User
    Join Date
    03-26-2007
    Posts
    92
    Bumping post.

    Any help would be appreciated!

  6. #6
    Registered User
    Join Date
    03-26-2007
    Posts
    92
    After some more trial and error, I modified the code from http://www.excelforum.com/showthread...ghlight=saveas to work for my command button.

    I used the below code:

    Private Sub CommandButton2_Click()
    'Saves file in Excel format
    
        Dim varFullName As Variant
        Dim strFileName As String
    
        Cancel = True
    
        strFileName = ThisWorkbook.Sheets("Test").Range("I3").Value
    
        varFullName = Application.GetSaveAsFilename(InitialFileName:=strFileName, _
                                                    fileFilter:="Microsoft Excel Workbook (*.xls), *.xls")
    
        If varFullName <> Cancel And varFullName <> False Then
              On Error GoTo FileNotSaved
                  Application.EnableEvents = False
                      ThisWorkbook.SaveAs Filename:=varFullName
                  Application.EnableEvents = True
        End If
    
        Exit Sub
    
    FileNotSaved:
    
        Application.EnableEvents = True
    
    End Sub

+ 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