Deze code werkte vroeger maar de laatste tijd krijg ik een foutmelding op
" .[a3] = Sheets(1).Name " nl op Sheets.
Met als melding :
Er wordt een variabele of procedure verwacht, geen module?
idem voor:
'ERROR op Sheets
'Compileerfout:
'For Each mag alleen worden uitgevoerd op een collectie-object
'of een matrix.
Iemand een suggestie?
Pierre
" .[a3] = Sheets(1).Name " nl op Sheets.
Met als melding :
Er wordt een variabele of procedure verwacht, geen module?
Code:
Sub Inhouds_opgave()
'Met dank aan Nate Oliver
Dim Ws As Worksheet, wsNw As Worksheet, N As Integer
Set wsNw = ThisWorkbook.Worksheets.Add(Before:=ThisWorkbook.Sheets(1))
With wsNw
On Error GoTo 2
1: .Name = "Inhoudsopgave"
On Error GoTo 0
.[A1] = "Bedrijfsnaam"
.[A1].Font.Size = 10
.[A1].Font.Bold = True
.[a2] = "Inhoudsopgave"
.[a2].Font.Size = 10
.[a2].Font.Bold = True
.[C4] = "Tabblad"
.[C4].Font.Size = 10
.[C4].Font.Bold = True
.[D4] = "Naam"
.[D4].Font.Size = 10
.[D4].Font.Bold = True
.Range("C:C").EntireColumn.AutoFit
N = 6
For Each Ws In ThisWorkbook.Worksheets
If Ws.Name <> .Name Then
.Cells(N, 4) = Ws.Name
With .Cells(N, 3)
.Value = N - 5
.HorizontalAlignment = xlCenter
End With
.Hyperlinks.Add _
Anchor:=.Cells(N, 4), _
Address:="", _
SubAddress:="'" & Ws.Name & "'!A1"
With Ws
.[a3] = Sheets(1).Name
.[a3].Hyperlinks.Add _
Anchor:=.Cells(3, 1), _
Address:="", _
SubAddress:="'" & Sheets(1).Name & "'!A1"
End With
N = N + 1
End If
Next
End With
Exit Sub
2: Application.DisplayAlerts = False
Sheets("Inhoudsopgave").Delete
Application.DisplayAlerts = True
GoTo 1
End Sub
idem voor:
'ERROR op Sheets
'Compileerfout:
'For Each mag alleen worden uitgevoerd op een collectie-object
'of een matrix.
Code:
Sub Inhouds_opgave2()
' van Wigi
Dim Ws As Worksheet
For Each Ws In Sheets
Range("A1").Offset(Ws.Index - 1).Value = Ws.Index
Range("B1").Offset(Ws.Index - 1).Value = Ws.Name
Next
End Sub
Iemand een suggestie?
Pierre
Laatst bewerkt: