简体   繁体   中英

Excel 2016 vba error 1004 - Aplication-defined or object defined error on index creation

I just start to have an issue with excel workbook that I first created using excel 2010 and used for almost 2 years, IT updated our office computers and now I have win10 with office 2016 installed.

VBA code that I am using:

Private Sub Worksheet_Activate()
Dim wSheet As Worksheet
Dim l As Long

l = 1

    With Me
        .Columns(1).ClearContents
        .Cells(1, 1) = "INDEX"
        .Cells(1, 1).Name = "Index"
    End With


    For Each wSheet In Worksheets
        If wSheet.Name <> Me.Name Then
            l = l + 1
                With wSheet
                    .Range("A1").Name = "Start_" & wSheet.Index
                    .Hyperlinks.Add Anchor:=.Range("A1"), Address:="", _
                    SubAddress:="Index", TextToDisplay:="Back to Index"
                End With

                Me.Hyperlinks.Add Anchor:=Me.Cells(l, 1), Address:="", _
                SubAddress:="Start_" & wSheet.Index, TextToDisplay:=wSheet.Name
        End If
    Next wSheet

End Sub

Lines that begins with .Hyperlinks.Add Anchor and SubAddress are marked yelow when I open debuger... Can you help me? Thank you...

Write Hyperlinks.Add press space and take a look at the parameters. Probably some of them are changed from 2010. Then adjust your code as per the change:

在此处输入图片说明

Or write debug.print wSheet.Index in the line above and check whether it gives a mistake. (Just guessing here.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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