VBA Run-time error '9': Subscript out of range; trying to activate another workbook

后端 未结 1 901
温柔的废话
温柔的废话 2021-01-14 08:26

I\'m trying to create a VBA in Excel 2010 that takes info from another spreadsheet that I\'m not allowed to alter and bring it over to the spreadsheet with my macro built in

1条回答
  •  感情败类
    2021-01-14 08:36

    Make sure the extension is correct. If it's a excel-2010 file like you indicate, you may need to update your code to reflect the extension of your "RITE 1624" file (e.g. .xlsx for a 2010 Excel workbook, .xlsm for a 2010 Excel macro-enabled workbook, or whatever the extension is.

    Sub BringUpWorkbook()
        Workbooks("RITE 1624.xlsx").Activate
    End Sub
    

    EDIT:

    To make sure you have the right name of the workbook, you can print the name of each workbook in an immediate window.

    Open up the VBA editor, and then press Ctrl+G to open the Immediate Window (or do View > Immediate window). Then run the following Macro:

    Sub OpenWkbkNames()
    
    For Each Workbook In Workbooks
        Debug.Print Workbook.Name
    Next
    End Sub
    

    Note that this will give you the names of all the open workbooks in the same Excel instance as your macro. If your RITE 1624 file is in a separate Excel instance, then the instance that your macro is in will not be able to see that file (and it won't appear in the output of the OpenWkbkNames code above). The simplest way to resolve this is to open all of your necessary files from the Excel instance that contains your macro.

    Sub BringUpWorkbook()
    
        Workbooks.Open("RITE 1624.xls").Activate
    End Sub
    

    0 讨论(0)
提交回复
热议问题