Error message when opening another sheet with vba from an marcro.

mattless1

Board Regular
Joined
Apr 1, 2011
Messages
102
Hi,
can any one help me with this issue.

i have two workbooks one is my order form & the other is the master sheet where my orders are transferred to to save a master copy of all orders.
Every thing was working on on my laptop running Office 2016, but when running on my office Pc running Office2013 i get an error saying the master sheet is already open reopening it will disacard any changes you have made.

can anyone help here.

here is a copy of the code that opens the master sheet.

VBA Code:
Sub CopyToMaster()
    Dim wMaster As Workbook, wMasterStr As String
    Dim shChristmas_Buchers_Orders As Worksheet
    Dim shMaster As Worksheet, shMasterStr As String
    Dim aCells() As String
    Dim sourceCells As String
    Dim nextRow As Range
    Dim i As Integer
    
    'Name of Master workbook
    wMasterStr = "Kilmac Master.xlsx"
    
    'Name of sheet in Master Workbook
    shMasterStr = "Sheet1"
    
    'Cells you want to copy from and paste into single row
    sourceCells = "C9,E8,J4,C7,H6,H7,H8,H9,I12,I13,I14,I15,I17,I18,I19,I20,D22,I22,I23,I24,C24,I26,I27,I28,I30,I31,I34,I35,I36,I39,I40,I41,I44,I45,I46,I47,I48,H42,I42,F51,G51,F52,G52,F53,G53,F54,G54,F55,G55,F56,F57,H57,I57"
    
    aCells = Split(sourceCells, ",")
    Set shInvoice = ActiveSheet
    For Each wMaster In Workbooks
        If wMaster.Name = wMasterStr Then
            Exit For
        End If
    Next
    
    If wMaster Is Nothing Then
        MsgBox "Please Contact Marco to open the master workbook first.", , wMasterStr & " not open"
        Exit Sub
    End If
    
    Set shMaster = wMaster.Sheets(shMasterStr)
    Set nextRow = shMaster.Cells(shMaster.Rows.Count, 1).End(xlUp)
    If nextRow.Value <> "" Then
        Set nextRow = nextRow.Offset(1, 0)
    End If
    nextRow.Value = nextRow.Row
    For i = 0 To UBound(aCells)
        shInvoice.Range(aCells(i)).Copy nextRow.Offset(0, i + 1)
        
    Next
    
    Dim wb As Workbook

Set wb = Application.Workbooks.Open("C:\Butchers Orders\Kilmac\Master Sheet\Kilmac Master.xlsx")
ActiveWorkbook.Save

wb.Close
    
End Sub
 

Attachments

  • Error.jpg
    Error.jpg
    7.8 KB · Views: 4

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Try this

VBA Code:
Sub CopyToMaster()
    Dim wMaster As Workbook, wMasterStr As String
    Dim shChristmas_Buchers_Orders As Worksheet
    Dim shMaster As Worksheet, shMasterStr As String
    Dim aCells() As String
    Dim sourceCells As String
    Dim nextRow As Range
    Dim i As Integer
    
    'Name of Master workbook
    wMasterStr = "Kilmac Master.xlsx"
    
    'Name of sheet in Master Workbook
    shMasterStr = "Sheet1"
    
    'Cells you want to copy from and paste into single row
    sourceCells = "C9,E8,J4,C7,H6,H7,H8,H9,I12,I13,I14,I15,I17,I18,I19,I20,D22,I22,I23,I24,C24,I26,I27,I28,I30,I31,I34,I35,I36,I39,I40,I41,I44,I45,I46,I47,I48,H42,I42,F51,G51,F52,G52,F53,G53,F54,G54,F55,G55,F56,F57,H57,I57"
    
    aCells = Split(sourceCells, ",")
    Set shInvoice = ActiveSheet
    For Each wMaster In Workbooks
        If wMaster.Name = wMasterStr Then
            Exit For
        End If
    Next
    
    If wMaster Is Nothing Then
        MsgBox "Please Contact Marco to open the master workbook first.", , wMasterStr & " not open"
        Exit Sub
    End If
    
    Set shMaster = wMaster.Sheets(shMasterStr)
    Set nextRow = shMaster.Cells(shMaster.Rows.Count, 1).End(xlUp)
    If nextRow.Value <> "" Then
        Set nextRow = nextRow.Offset(1, 0)
    End If
    nextRow.Value = nextRow.Row
    For i = 0 To UBound(aCells)
        shInvoice.Range(aCells(i)).Copy nextRow.Offset(0, i + 1)
    Next
    
    wMaster.Close True
End Sub
 
Upvote 0
Do you have any other macro running?

I don't see in your macro where you are trying to open the book "Ballsbridge Master.xlsx"
 
Upvote 0
Hi,

Yes i have a few running. but they all work in office 2016.


VBA Code:
Sub Masteropen()
Application.ScreenUpdating = False
Workbooks.Open ("C:\Butchers Orders\Kilmac\Master Sheet\Kilmac Master.xlsx")
ActiveWindow.WindowState = xlMinimized
ThisWorkbook.Activate
Application.ScreenUpdating = True
End Sub


thanks
 
Upvote 0
You can run the macro in a new book without executing any other code.
That is, isolate the code in an execution.
 
Upvote 0

Forum statistics

Threads
1,214,936
Messages
6,122,340
Members
449,079
Latest member
rocketslinger

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