Removing Option Explicit crashes excel

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,282
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi All

Was wondering if anyone else encountered any issues with this. I have multiple modules

I have noticed that If I remove that line of code it crashes my whole system so was hoping someOne could explain if this is a known issue and why this happens
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
option explicit has advantages and disadvantages.
As starter, i strongly advice to use it and declare all variables as string, integer, long, range, variant, ... .
But later, as you are more experienced, you can be less rigide.
When excel crashes, then i look why and sometimes declare that variable.

For example, to prevent situations where you look something in a range and it isn't there and so you cope with error messages
VBA Code:
dim c as range
on error resume next
set c=range("A1:Z100").find what:="impossible value"
on error goto 0
if c is nothing then ...

But now you started a big discussion between believers and non-believers ...
 
Upvote 0
You don't need an error handler with Find though... ;)
 
Upvote 0
Thank you
So by not declaring a variable excel can crash?

Mine crashes when looping through connections as ive not defined what a con is - im not sure what to define as

For eg

For each con in activeworkbook.connections
 
Upvote 0
This is my code which often comes up with a busy connection message too which i need to get around

Sub Refresh()

Dim conn As Variant

For Each conn In ActiveWorkbook.Connections
conn.ODBCConnection.BackgroundQuery = False
Next conn

ActiveWorkbook.RefreshAll
End Sub
 
Upvote 0
Connections, i'm not familiar with that, sorry.
 
Upvote 0

Forum statistics

Threads
1,206,946
Messages
6,075,790
Members
446,157
Latest member
mysteryg45

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