on workbook open error

d0wnt0wn

Well-known Member
Joined
Oct 28, 2002
Messages
771
Hi Guys I am getting this error when my workbook opens. This started happening when we upgraded our office to 2016

else without if

and it brings me here

If ActiveWorkbook.name = "Roof System.xlsm" Then Range("J1").Formula = "=today()"
Else
Exit Sub
End If

not sure why this is happening... any ideas?... essentially I want this cel left alone unless the workbook is named Roof System.xlsm
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Just get rid of the Else & the Exit Sub lines
 
Upvote 0
What Fluff said (if you don't have any code after if statement). Or, move the statement(s) in then block to a new line.

Reason: IF-THEN has two syntaxes - one line and multiline.

One line IF-THEN (doesn't need END IF keywords)
Code:
IF conditions THEN code ELSE code
Multiline IF-THEN (needs END IF keywords to end)
Code:
IF conditions THEN
    code
ELSE
    code
END IF
 
Last edited:
Upvote 0
These errors can occur because the Ifs/EndIfs are wrong anywhere in the code. As well as Withs/EndWiths and Do/Whiles Loop/Untils or any kind of control block.

You should post the whole code.

Note: and, as noted above, there are two syntaxes, one for single line and one for multiline if statements!! Good catch.
 
Last edited:
Upvote 0
As posted above, remove the End If as well
 
Upvote 0
This is nothing to do with the upgrade, try this.
Code:
If ActiveWorkbook.name = "Roof System.xlsm" Then Range("J1").Formula = "=today()"
Or this.
Code:
If ActiveWorkbook.name = "Roof System.xlsm" Then 
    Range("J1").Formula = "=today()"
Else
    Exit Sub
End If
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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