Results 1 to 3 of 3

Change Macro to save file in different folder

Threaded View

  1. #1
    Registered User
    Join Date
    03-13-2013
    Location
    Wichita,KS
    MS-Off Ver
    365 Aps for Enterprise
    Posts
    60

    Change Macro to save file in different folder

    The macro below is SUPPOSED to save only the "Calculation" sheet to the file path listed in cell N5 (Calculation Sheet) and then show a message box showing where it was saved. For some reason the file is saving to either the last opened folder or the "My Documents" folder (no matter what I put in cell "N5" on the "Calculation sheet). However, the message box shows the file path that I have typed in cell N5. I cobbled this code together and have limited experience at VBA so it's time to call in an expert.

    See attached worksheet.

    Sheets("Calculation").Select
        Dim FileExtStr As String
        Dim FileFormatNum As Long
        Dim Sourcewb As Workbook
        Dim Destwb As Workbook
        Dim TempFilePath As String
        Dim TempFileName As String
    
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
        End With
    
        Set Sourcewb = ActiveWorkbook
    
        'Copy the sheet to a new workbook
        ActiveSheet.Copy
        Set Destwb = ActiveWorkbook
    
        'Determine the Excel version and file extension/format
        With Destwb
            If Val(Application.Version) < 12 Then
                'You use Excel 97-2003
                FileExtStr = ".xls": FileFormatNum = -4143
            Else
                'You use Excel 2007-2013
                    FileExtStr = ".xlsx": FileFormatNum = 51
                End If
        End With
    
        'Change all cells in the worksheet to values if you want
        With Destwb.Sheets(1).UsedRange
                .Cells.Copy
                .Cells.PasteSpecial xlPasteValues
                .Cells(1).Select
            End With
            Application.CutCopyMode = False
    
        'Save the new workbook and close it
        TempFilePath = Sheets("Calculation").Range("N5").Value
        TempFileName = Range("N4").Value
        
        With Destwb
            .SaveAs TempFileName & FileExtStr, FileFormat:=FileFormatNum
            .Close SaveChanges:=False
        End With
    
        MsgBox "You can find the new file in " & TempFilePath
    
        With Application
            .ScreenUpdating = True
            .EnableEvents = True
        End With
    
    End Sub
    I will actually need two different variations of this macro: 1). Macro as noted in my description above. 2). Macro to do basically the same thing (insert file name listed in "N4", in the file name box and go to file path listed in "N5") but stop at the SaveAs file dialog box so that the user can change the file name manually or the file path if they want to.

    Thanks in advance for your help.

    Take care.
    Marvin
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro to save file each day to specific folder with date in name
    By sjhf in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-13-2013, 03:24 PM
  2. [SOLVED] macro to save file to specific folder with file name from cell reference
    By mezza89 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-06-2013, 11:32 AM
  3. [SOLVED] save macro with specific folder and file name and type
    By wolfm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2013, 10:08 AM
  4. [SOLVED] Macro to save file as XLSX in the same folder from where it originated
    By balandri in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-07-2013, 02:28 PM
  5. Replies: 6
    Last Post: 08-11-2006, 03:41 PM

Tags for this Thread

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