Ich habe Probleme mit meinem Makro, es läuft reibungslos vom Desktop aber wenn ich die gleiche Datei im Netzlaufwerk, andere Benutzer konfrontiert Runtime error 91 Object variable or With block variable not set
.
Lassen Sie mich auch wissen, wie geschützte Ansicht mit Makro entfernen.VBA Laufzeitfehler '91': Objektvariable oder mit Blockvariable nicht gesetzt
Ihre Hilfe für folgenden Code benötigen:
In Modul
Sub UnhideAllSheets()
'Unhide all sheets in workbook.
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Visible = xlSheetVisible
Next ws
End Sub
Sub HideAllSheets()
'Unhide all sheets in workbook.
Call UnhideAllSheets
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If InStr(1, ws.Name, "START", vbTextCompare) = 0 _
And InStr(1, ws.Name, "Data", vbTextCompare) = 0 Then
ws.Visible = xlVeryHidden
End If
Next ws
End Sub
Sub DRD()
Dim ws As Worksheet
Call HideAllSheets
'If VBA.Environ("Username") = "140736TJ" Then
'Sheets("8.Generator").Visible = xlSheetVisible
'Sheets("8.Generator").Select
With ActiveWorkbook.Worksheets
Select Case VBA.Environ("Username")
Case "130349TJ", "130355TJ"
Sheets("1.Large MCH").Visible = xlSheetVisible
Sheets("1.Large MCH").Select
Case "140646TJ"
Sheets("2.Large FAB").Visible = xlSheetVisible
Sheets("2.Large FAB").Select
Case "130361TJ"
Sheets("3.Blade").Visible = xlSheetVisible
Sheets("3.Blade").Select
Case "120243TJ"
Sheets("4.Nozzle").Visible = xlSheetVisible
Sheets("4.Nozzle").Select
Case "130360TJ", "146061tc"
Sheets("5.T.Assy").Visible = xlSheetVisible
Sheets("5.T.Assy").Select
Case "110206TJ"
Sheets("6.Rotor").Visible = xlSheetVisible
Sheets("6.Rotor").Select
Case "120237TJ"
Sheets("7. Control Valve").Visible = xlSheetVisible
Sheets("7. Control Valve").Select
Case "140736TJ", "110088TJ", "130344TJ"
Call UnhideAllSheets
Sheets("DRD Index Consolidation").Select
Case "120234TJ"
Call UnhideAllSheets
Sheets("DRD Index Consolidation").Select
Call StopDeleteRowCols
Case Else
MsgBox "ACCESS DENIED"
ActiveWorkbook.Close
Call ResetDeleteRowCols
End Select
End With
End Sub
Sub StopDeleteRowCols()
Dim ctl As CommandBarControl
For Each ctl In Application.CommandBars.FindControls(ID:=293)
ctl.Enabled = False
Next ctl
For Each ctl In Application.CommandBars.FindControls(ID:=294)
ctl.Enabled = False
Next ctl
For Each ctl In Application.CommandBars.FindControls(ID:=296)
ctl.Enabled = False
Next ctl
For Each ctl In Application.CommandBars.FindControls(ID:=3181)
ctl.Enabled = False
Next ctl
For Each ctl In Application.CommandBars.FindControls(ID:=292)
ctl.Enabled = False
Next ctl
For Each ctl In Application.CommandBars.FindControls(ID:=3125)
ctl.Enabled = False
Next ctl
For Each ctl In Application.CommandBars.FindControls(ID:=21)
ctl.Enabled = False
Next ctl
For Each ctl In Application.CommandBars.FindControls(ID:=945)
ctl.Enabled = False
Next ctl
For Each ctl In Application.CommandBars.FindControls(ID:=4)
ctl.Enabled = False
Next ctl
End Sub
Sub ResetDeleteRowCols()
Dim ctl As CommandBarControl
For Each ctl In Application.CommandBars.FindControls(ID:=293)
ctl.Enabled = True
Next ctl
For Each ctl In Application.CommandBars.FindControls(ID:=294)
ctl.Enabled = True
Next ctl
For Each ctl In Application.CommandBars.FindControls(ID:=296)
ctl.Enabled = True
Next ctl
For Each ctl In Application.CommandBars.FindControls(ID:=3181)
ctl.Enabled = True
Next ctl
For Each ctl In Application.CommandBars.FindControls(ID:=292)
ctl.Enabled = True
Next ctl
For Each ctl In Application.CommandBars.FindControls(ID:=3125)
ctl.Enabled = True
Next ctl
For Each ctl In Application.CommandBars.FindControls(ID:=21)
ctl.Enabled = True
Next ctl
For Each ctl In Application.CommandBars.FindControls(ID:=945)
ctl.Enabled = True
Next ctl
For Each ctl In Application.CommandBars.FindControls(ID:=4)
ctl.Enabled = True
Next ctl
End Sub
Private Sub Workbook_Open()
DRD
End Sub
Welche Zeile gibt den Fehler? –