View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
monir monir is offline
external usenet poster
 
Posts: 215
Default Assign Value to Module Level Variable

There are 8 VBA regular macros (macro1 to macro8) in a single module. Each
macro includes the following 3 statements:
..............................................
.....Dim myOptFile As String 'statement # 1
.....myOptFile = "Test.xls" 'statement # 2
.....Call myMacro (myOptFile) 'statement # 3
.............................................

All macros work fine.

Now, for easy maintenance, I moved the procedure declaration statement # 1
to the module Declarations section at the top, and deleted same from the 8
macros.
Then I left the assignment statement # 2 in one macro (macro1) and deleted
same from the other macros.

When I tried to run macro3(), I got "Run-time error '13': type mismatch",
with reference to myOptFile in the call statement.

Isn't that how one makes a variable visible to all procedures in a module ?
Declare the variable at the top, and assign it in any single procedure.

Thank you.