Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 超链接。跟随错误:运行时错误“9”:下标超出范围_Vba_Excel - Fatal编程技术网

Vba 超链接。跟随错误:运行时错误“9”:下标超出范围

Vba 超链接。跟随错误:运行时错误“9”:下标超出范围,vba,excel,Vba,Excel,激活超链接后,我在图纸选择行中得到的下标超出范围 'Hyperlink aktivieren und Sheet Overview Results Selection.Hyperlinks(1).Follow NewWindow:=True, AddHistory:=True Worksheets("Overview Results").Select AuswerteWb = ActiveWorkbook.Name 'ActiveWindow.Close 问题是,我有一个宏,它应该使用文件的路

激活超链接后,我在图纸选择行中得到的下标超出范围

'Hyperlink aktivieren und Sheet Overview Results
Selection.Hyperlinks(1).Follow NewWindow:=True, AddHistory:=True
Worksheets("Overview Results").Select
AuswerteWb = ActiveWorkbook.Name
'ActiveWindow.Close
问题是,我有一个宏,它应该使用文件的路径作为超链接,并从超链接文件中选择图纸概览结果

但我明白了

运行时错误“9”:下标超出范围

为什么要使用超链接。遵循而不是工作簿。打开?如果使用超链接打开新工作簿,则需要执行以下操作:

Dim OpenedFile as Workbook

' Skip any errors that would occur with a null link
On Error Resume Next
Set OpenedFile = Workbooks.Open(Selection.Value)
On Error GoTo 0

' Ensure that the file is set before operating on it
If Not OpenedFile Is Nothing Then
    Dim TargetWorksheet as Worksheet

    On Error Resume Next
    Set TargetWorksheet = OpenedFile.Worksheets("Overview Results")
    On Error GoTo 0

    ' We use the same Nothing check before operating on the worksheet
    If Not TargetWorksheet Is Nothing Then
        TargetWorksheet.Activate
    End If
End If

AuswerteWb = OpenedFile.Name
'ActiveWindow.Close

我强烈鼓励你学习如何限定你的陈述。例如,工作表是一个不合格的陈述,因为这会给你带来很多麻烦。类似地,避免选择、选择、激活、活动工作簿等。

是否设置了选项Base 1?当您引用不存在的工作表名称时,可能会发生此错误。再次检查工作表名称并检查前导和尾随空格。请不要忘记将答案标记为正确答案:。我很高兴它对你有用。