简体   繁体   English

VBA错误运行时错误9下标超出范围

[英]VBA Error Run time error 9 Subscript Out of range

I am getting Run time error 9 我收到运行时错误9

Sub Conway()
Dim aRng As Range
Dim Data As Range, c As Collection
Dim v As String, i As Long, ary
Set c = New Collection
    Path = "D:\InTransit DR Report\"
    RawFile = Application.GetOpenFilename(, , "Please Select InTransit Raw WorkBook:")
    Application.DisplayAlerts = False
    If RawFile = "False" Then
        MsgBox "Please select appropriate Final Output file", vbCritical, "Nike InTransit DR Automation"
        Exit Sub
    Else
        Workbooks.Open RawFile, True, False
    Application.Wait (10)
    Application.Visible = False
    Application.Visible = True
    Application.WindowState = xlMaximized
    ActiveWindow.WindowState = xlMaximized
    End If
    Sheets("In-Transit").Select 'Getting error here

We are dealing with two workbooks: 我们正在处理两个工作簿:

  1. the workbook containing the macro (wb1) 包含宏(wb1)的工作簿
  2. the workbook opened by the macro (wb2) (wb2)打开的工作簿

Once wb2 has been opened, it becomes the Active workbook and the line: 一旦打开了wb2 ,它将成为Active工作簿和以下行:

Sheets("In-Transit").Select

will only work if that sheet is in wb2 . 仅在该工作表在wb2时才有效 If the sheet is in the original workbook (wb1) , that workbook must be re-activated beforre the sheet can be Selected . 如果工作表在原始工作簿(wb1)中 ,则必须重新激活该工作簿,然后才能Selected Also make sure that there are no extra spaces in the sheetname. 还要确保工作表名称中没有多余的空格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM