Welcome Msg to Only Occur Once Upon Opening

Ottsel

Board Regular
Joined
Jun 4, 2022
Messages
167
Office Version
  1. 365
Platform
  1. Windows
I must be overlooking a very simple thing, but I'm still a novice at VBA, so if someone could point out what I'm overlooking I'd greatly appreciate it.

E1 is hidden on the worksheet named "August" - the name is actually "EE August". I renamed it within the VBA editor, so even if the worksheet name is changed, then it can't mess-up the macro. I have this within the "ThisWorkbook" under Microsoft Excel Objects.

VBA Code:
Private Sub Workbook_Open()
'...to avoid vb error msg
On Error Resume Next
    If Worksheets("August").Range("E1").Value > 0 Then
        MsgBox "Welcome! Let's get started"
    Else
    End If
    '...avoid this msg repeating
    Range("E1").Value = "0"
End Sub
The value at the first opening of the workbook is 1.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
You don't have any sheet reference on this line here:
VBA Code:
   Range("E1").Value = "0"
so it will update cell E1 on whatever sheet is active when the file is opened, which may not be your "August" sheet.
 
Upvote 0
You don't have any sheet reference on this line here:
VBA Code:
   Range("E1").Value = "0"
so it will update cell E1 on whatever sheet is active when the file is opened, which may not be your "August" sheet.
Ah, overlooked that. Appreciate that. But, I'm still encountering an issue where the message will occur even after E1 is zero.
 
Upvote 0
I would recommend add a file save command after changing the value of E1 to 0.
Otherwise, if they close the workbook without saving it, that change to 0 will not be saved and it will resort back to what it was before.

Also, get rid of this line, especially when debugging.
VBA Code:
On Error Resume Next
You may be encountering errors, but you are ignoring them, so you will never know what they are!

The way you have written your code, I think you are going to have problems if your sheet is not named exactly "August".

I think you would be better to refer to the sheet by the name shown in the VBA Project Explorer, i.e.

If this is what you see in VBA Project Explorer:
1659472207062.png


refer to it by the name shown there, i.e.
change these references:
VBA Code:
Worksheets("August").Range("E1")
to this:
VBA Code:
Sheet1.Range("E1")

That "Sheet1" reference is the thing that won't change if you change the name of the sheet.
 
Upvote 0
Solution
I would recommend add a file save command after changing the value of E1 to 0.
Otherwise, if they close the workbook without saving it, that change to 0 will not be saved and it will resort back to what it was before.

Also, get rid of this line, especially when debugging.
VBA Code:
On Error Resume Next
You may be encountering errors, but you are ignoring them, so you will never know what they are!

The way you have written your code, I think you are going to have problems if your sheet is not named exactly "August".

I think you would be better to refer to the sheet by the name shown in the VBA Project Explorer, i.e.

If this is what you see in VBA Project Explorer:
View attachment 70667

refer to it by the name shown there, i.e.
change these references:
VBA Code:
Worksheets("August").Range("E1")
to this:
VBA Code:
Sheet1.Range("E1")

That "Sheet1" reference is the thing that won't change if you change the name of the sheet.
That was the ticket. Thank you Joe.
 
Upvote 0
You are welcome.
Glad I was able to help.
 
Upvote 0

Forum statistics

Threads
1,215,758
Messages
6,126,718
Members
449,332
Latest member
nokoloina

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