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

在激活超链接后,我在页面select行中得到下标超出范围

'Hyperlink aktivieren und Sheet Overview Results Selection.Hyperlinks(1).Follow NewWindow:=True, AddHistory:=True Worksheets("Overview Results").Select AuswerteWb = ActiveWorkbook.Name 'ActiveWindow.Close 

问题是我有一个macros应该使用文件的path作为超链接,并从超链接文件中select表格“overview results”。

但是我明白了

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

为什么使用Hyperlinks.Follow而不是Workbooks.Open ? 如果您使用超链接打开一个新的工作簿,您将需要执行如下操作:

 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 

我强烈build议你了解你的陈述的合格性(例如, Worksheets("")是一个无条件的陈述),因为这会造成你很多的麻烦。 同样,避免SelectionSelectActivateActiveWorkbook