sspatriots
Well-known Member
- Joined
- Nov 22, 2011
- Messages
- 585
- Office Version
- 365
- Platform
- Windows
Hi,
I get the "Run-time error '91': Object variable or With block variable not set" error when I run my code below". The error occurs at the line directly below.
Any help would be much appreciated. Thank you, SS
Code I'm trying to run:
I get the "Run-time error '91': Object variable or With block variable not set" error when I run my code below". The error occurs at the line directly below.
VBA Code:
With wbCurUsers.Worksheets(1)
Any help would be much appreciated. Thank you, SS
Code I'm trying to run:
VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim wbCurUsers As Workbook
Dim strUser As String
strUser = Environ("UserName")
Set wbCurUsers = Workbooks.Open(Filename:=ThisWorkbook.Path & "\Current Users.xlsx")
With wbCurUsers.Worksheets(1)
.Columns(1).Replace What:=strUser, Replacement:="", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End With
wbCurUsers.Close SaveChanges:=True
End Sub