kt_mr_excel
New Member
- Joined
- Sep 24, 2021
- Messages
- 15
- Office Version
- 365
- 2016
- Platform
- Windows
I'm obviously very new to VBA in Access and need some help with a very simple If statement based on the value of a specified cell in the active Excel worksheet. My many attempts have included every type of declaration I could find in online examples and many different range expressions but always result in an "error 91 - Object variable or With block variable not set". I also tried using a With block without any luck. Here's my simple sub - I thought that this approach would not require declaration of any variables, but obviously I thought wrong. Any help would be appreciated. (Note: Excel 16.0 Object Library is referenced)
Sub MySub()
If Excel.Application.ActiveSheet.Range("A1").Value = "String to match" Then
MsgBox "Message string"
End If
End Sub
Sub MySub()
If Excel.Application.ActiveSheet.Range("A1").Value = "String to match" Then
MsgBox "Message string"
End If
End Sub