Macro error- Expected variable or procedure, not module

Marlowwe

New Member
Joined
Jan 12, 2016
Messages
46
Hello,

I found this usefull macro and mz VBA Editor gives me error: Expected variable or procedure, not module.

and Highlight Sheets("Index").Delete

Code:
Sub CreateIndex()
'updateby Extendoffice 20150914
    Dim xAlerts As Boolean
    Dim I  As Long
    Dim xShtIndex As Worksheet
    Dim xSht As Variant
    xAlerts = Application.DisplayAlerts
    Application.DisplayAlerts = False
    On Error Resume Next
    Sheets("Index").Delete
    On Error GoTo 0
    Set xShtIndex = Sheets.Add(Sheets(1))
    xShtIndex.name = "Index"
    I = 1
    Cells(1, 1).Value = "INDEX"
    For Each xSht In ThisWorkbook.Sheets
        If xSht.name <> "Index" Then
            I = I + 1
            xShtIndex.Hyperlinks.Add Cells(I, 1), "", "'" & xSht.name & "'!A1", , xSht.name
        End If
    Next
    Application.DisplayAlerts = xAlerts
End Sub

or here: Sheets.Add before:=Sheets(1)

Code:
Sub CreateIndex2()
Dim sheetnum As Integer
Sheets.Add before:=Sheets(1)
For sheetnum = 2 To Worksheets.Count
 ActiveSheet.Hyperlinks.Add _
 Anchor:=Cells(sheetnum - 1, 1), _
 Address:="", _
 SubAddress:="'" & Worksheets(sheetnum).name & "'!A1", _
 TextToDisplay:=Worksheets(sheetnum).name
Next sheetnum
ActiveWindow.DisplayGridlines = False
End Sub
Where is the problem ? Thank you
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Does this help?

Looks like a naming conflict?

NO.

I rename macro several times and I get the same error. :(

But when I Run the macro from Other file (.XLSM) then my PERSONAL.XLSB file the macro run normaly without error.

I have a lots of macros (200) in my PERSONAL.XLSB for creating or testing, so Somewhere have to be a thing which gives me the error ?
 
Last edited:
Upvote 0
It sounds like you have a module called sheets in your Personal.xlsb file.
Change the name of the module & try again.
You should never use VBA keywords for Modules, subs, or variables as it can cause problems like this.
 
Upvote 0
It sounds like you have a module called sheets in your Personal.xlsb file.
Change the name of the module & try again.
You should never use VBA keywords for Modules, subs, or variables as it can cause problems like this.

WOW, thanks. IT Works.

I had a Module named Sheets_Tested. I renamed and it is Ok,

Thanks Fluff :-)
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top