Save new workbook in same location as source workbook code

Samson92

New Member
Joined
May 27, 2019
Messages
18
I have a workbook that has multiple sheets, and I have a macro that will copy and paste three select sheets into a new workbook. I'd like to add an automatic save on the new workbook, but i'd like it to save in two places. One being the same place as the workbook that runs the macro, the other being in G:\MI\. If possible, i'd like the name of the new workbook to be "BR - today's date". Any help would be appreciated. Here's the code I am working off now.

Code:
Sub CopyInNewWB()    Dim wbO As Workbook, wbN As Workbook


    On Error GoTo ErrHandler


    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Application.DisplayAlerts = False


    Set wbO = ActiveWorkbook
    Set wbN = Workbooks.Add


    wbO.Sheets("Tracking").Copy wbN.Sheets(1)
    With ActiveSheet.UsedRange
       .Value = .Value
    End With


    wbO.Sheets("Bridge").Copy wbN.Sheets(2)
    With ActiveSheet.UsedRange
       .Value = .Value
    End With


    wbO.Sheets("Overview (Age)").Copy wbN.Sheets(3)
    With ActiveSheet.UsedRange
       .Value = .Value
    End With


    wbN.Sheets("Sheet1").Delete
    wbN.Sheets("Bridge").Activate


    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    Application.DisplayAlerts = True


ErrHandler:
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    Application.DisplayAlerts = True
       
 
        
End Sub

Thanks.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Try:
Code:
Sub CopyInNewWB()
    Dim wbO As Workbook, wbN As Workbook, ws As Worksheet
    On Error GoTo ErrHandler
    With Application
        .ScreenUpdating = False
        .Calculation = xlCalculationManual
        .DisplayAlerts = False
    End With
    Set wbO = ThisWorkbook
    Sheets(Array("Tracking", "Bridge", "Overview (Age)")).Copy
    For Each ws In Sheets
        ws.UsedRange.Value = ws.UsedRange.Value
    Next ws
    Sheets("Bridge").Activate
    With ActiveWorkbook
        .SaveAs Filename:=wbO.Path & Application.PathSeparator & "MI\BR-" & Date & ".xlsx", FileFormat:=51
        .SaveAs Filename:="G:\MI\BR-" & Date & ".xlsx", FileFormat:=51
    End With
    With Application
        .ScreenUpdating = True
        .Calculation = xlCalculationAutomatic
        .DisplayAlerts = True
    End With
ErrHandler:
    With Application
        .ScreenUpdating = True
        .Calculation = xlCalculationAutomatic
        .DisplayAlerts = True
    End With
End Sub
 
Last edited:
Upvote 0
Thanks for that suggestion, but it doesn't save anything, still just opens the new workbook with the name Book2 and doesn't save. Is there anything else I need to add?
 
Upvote 0
Try:
Code:
Sub CopyInNewWB()
    Dim wbO As Workbook, wbN As Workbook, ws As Worksheet
    With Application
        .ScreenUpdating = False
        .Calculation = xlCalculationManual
        .DisplayAlerts = False
    End With
    Set wbO = ThisWorkbook
    Sheets(Array("Tracking", "Bridge", "Overview (Age)")).Copy
    For Each ws In Sheets
        ws.UsedRange.Value = ws.UsedRange.Value
    Next ws
    Sheets("Bridge").Activate
    With ActiveWorkbook
        .SaveAs Filename:=wbO.Path & Application.PathSeparator & "BR-" & Replace(Date, "/", "-") & ".xlsx", FileFormat:=51
        .SaveAs Filename:="G:\MI\BR-" & Date & ".xlsx", FileFormat:=51
    End With
    With Application
        .ScreenUpdating = True
        .Calculation = xlCalculationAutomatic
        .DisplayAlerts = True
    End With
End Sub
 
Upvote 0
I tested the macro on a dummy workbook and it worked properly. Which line of code is highlighted when you click "Debug"? I think that it would be easier to help and test possible solutions if I could work with your actual file which includes any macros you are currently using. Perhaps you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0

Forum statistics

Threads
1,224,834
Messages
6,181,243
Members
453,026
Latest member
cknader

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top