Appreciate help with understanding how a VBA macro that works fine in Excel 2010 and 2013, but that generates an error (Run-time error '1004': Application-defined or object-defined error) when executing in version 2016 explicitly.
The macro is embedded with a sheet in a workbook (the "Index" sheet), rather than as a module. The indexing hyperlink feature seems common with workbooks containing large numbers of worksheets. I've tried looking through the forum for exact same problem but couldn't find so I'm hoping I can find a solution on the forum.
The snippet below shows the area of issue in the code. wSheet is dimensioned as a worksheet variable at the start of the program and is used to cycle through the various spreadsheets in the workbook. A test (not shown) is first conducted to ensure the Index sheet itself is not included in the rotation. The program halts with the error mentioned above at the ".Hyperlinks.Add..." line.
With wSheet
.Range("A1").Name = "Start_" & wSheet.Index 'Sets up naming A1 cell in each spreadsheet tab
'Hyperlink lines below writes the hyperlink in each spreadsheet tab with reference back to Index sheet
.Hyperlinks.Add Anchor:=.Range("A1"), Address:="", _
SubAddress:="Index", TextToDisplay:="INDX"
End With
I've tried various things like a ".Activate" after the ".Range" line, but to no avail. What does work is if I do a manual controlled hyperlink addition that doesn't use the wSheet variable.
Sheets.Add.Name = "Test1"
Sheets("Test1").Range("A1").Value = "Hi"
Sheets("Test1").Range("A1").Name = "HiName"
Sheets("Test1").Hyperlinks.Add Anchor:=Sheets("Test1").Range("A1"), Address:="", SubAddress:="Index", TextToDisplay:="INDX"
Any suggestions or answers regarding why I'm not having this issue in version 2016?
Thanks,
Clay
The macro is embedded with a sheet in a workbook (the "Index" sheet), rather than as a module. The indexing hyperlink feature seems common with workbooks containing large numbers of worksheets. I've tried looking through the forum for exact same problem but couldn't find so I'm hoping I can find a solution on the forum.
The snippet below shows the area of issue in the code. wSheet is dimensioned as a worksheet variable at the start of the program and is used to cycle through the various spreadsheets in the workbook. A test (not shown) is first conducted to ensure the Index sheet itself is not included in the rotation. The program halts with the error mentioned above at the ".Hyperlinks.Add..." line.
With wSheet
.Range("A1").Name = "Start_" & wSheet.Index 'Sets up naming A1 cell in each spreadsheet tab
'Hyperlink lines below writes the hyperlink in each spreadsheet tab with reference back to Index sheet
.Hyperlinks.Add Anchor:=.Range("A1"), Address:="", _
SubAddress:="Index", TextToDisplay:="INDX"
End With
I've tried various things like a ".Activate" after the ".Range" line, but to no avail. What does work is if I do a manual controlled hyperlink addition that doesn't use the wSheet variable.
Sheets.Add.Name = "Test1"
Sheets("Test1").Range("A1").Value = "Hi"
Sheets("Test1").Range("A1").Name = "HiName"
Sheets("Test1").Hyperlinks.Add Anchor:=Sheets("Test1").Range("A1"), Address:="", SubAddress:="Index", TextToDisplay:="INDX"
Any suggestions or answers regarding why I'm not having this issue in version 2016?
Thanks,
Clay