Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Passig a variable from one module to another

I am attempting to pass a variable value from one module to another module in
another worksheet.

I first collect the values based on user input in macro 1and then call
macro2 from my "PERSONAL.xls" file to continue processing. Unfortunately, I
need to capture some of the data which was used in the first macro and pass
it along to the 2nd macro.

I've declared the variables "up top" as follows:

Option Explicit
Public xlfile_drive As String
Public period_end As String
Public open_file As String
Public open_file_name As String
Public continueprompt As String

Sub Create_Return_File(xlfile_drive, period_end, open_file, open_file_name,
continueprompt)



periodend = InputBox("Enter reporting month-end in this sample format:
2007-Aug")
xlfile_drive = "T:\mktg\star keystone reporting\Keystone\" & periodend &
"\"
ChDir xlfile_drive
open_file_name = "ROR Series ATC and Models Report-" & Right(periodend,
3) & "-" & Mid(periodend, 3, 2) & ".xls"
open_file = xlfile_drive & open_file_name
....

Further down, I then call the 2nd macro as follows:

Call Add_EPL_Data
....
Public Sub Add_EPL_Data(open_file_name, open_file)
Application.Run "'Personal.xls'!Add_EPL_Returns"
End Sub

Still, the macro is not working and is giving me the error message:

Compile error -- variable not defined.

I had thought, however, that defining it at the global level outside the
subprocedure would resolve this problem?




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Passig a variable from one module to another

First off, you have a scoping problem. When you put names on the Sub line,
you are defining those variables for that sub. since they have the same
names as the public variables, instide that sub you reference the local ones
and in other subs you reference the public global ones. This will obviously
cause you problems.

Second, you define the sub "Add_EPL_Data" to have 2 parameters but you don't
pass anything when you call it.

Third, how is Add_EPL_Data defined in personals? Does it have parameters?
If it is defined the same as this one, then remove the local funcation.

When you call "Create_Return_File" do you pass in the parameters?

I suspect what you want is something like this:
Option Explicit
Public xlfile_drive As String
Public period_end As String
Public open_file As String
Public open_file_name As String
Public continueprompt As String

Sub Create_Return_File
dim xlfile_drive as String
dim period_end as String
dim open_file as String
dim open_file_name as String
dim continueprompt as String



periodend = InputBox("Enter reporting month-end in this sample format:
2007-Aug")
xlfile_drive = "T:\mktg\star keystone reporting\Keystone\" & periodend &
"\"
ChDir xlfile_drive
open_file_name = "ROR Series ATC and Models Report-" & Right(periodend,
3) & "-" & Mid(periodend, 3, 2) & ".xls"
open_file = xlfile_drive & open_file_name
....

Further down, I then call the 2nd macro as follows:

Call Add_EPL_Data open_file_name, open_file
....

Peter Richardson

"Eric_G" wrote:

I am attempting to pass a variable value from one module to another module in
another worksheet.

I first collect the values based on user input in macro 1and then call
macro2 from my "PERSONAL.xls" file to continue processing. Unfortunately, I
need to capture some of the data which was used in the first macro and pass
it along to the 2nd macro.

I've declared the variables "up top" as follows:

Option Explicit
Public xlfile_drive As String
Public period_end As String
Public open_file As String
Public open_file_name As String
Public continueprompt As String

Sub Create_Return_File(xlfile_drive, period_end, open_file, open_file_name,
continueprompt)



periodend = InputBox("Enter reporting month-end in this sample format:
2007-Aug")
xlfile_drive = "T:\mktg\star keystone reporting\Keystone\" & periodend &
"\"
ChDir xlfile_drive
open_file_name = "ROR Series ATC and Models Report-" & Right(periodend,
3) & "-" & Mid(periodend, 3, 2) & ".xls"
open_file = xlfile_drive & open_file_name
...

Further down, I then call the 2nd macro as follows:

Call Add_EPL_Data
...
Public Sub Add_EPL_Data(open_file_name, open_file)
Application.Run "'Personal.xls'!Add_EPL_Returns"
End Sub

Still, the macro is not working and is giving me the error message:

Compile error -- variable not defined.

I had thought, however, that defining it at the global level outside the
subprocedure would resolve this problem?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Passig a variable from one module to another

I haven't examined the workings of your code yet, but you are getting
a Variable Not Defined error because you have a variable named wrong,
which is not allowed when using Option Explicit. You declared
variable period_end with an underscore, but in your code you are using
periodend with no underscore.
Eric_G wrote:
I am attempting to pass a variable value from one module to another module in
another worksheet.

I first collect the values based on user input in macro 1and then call
macro2 from my "PERSONAL.xls" file to continue processing. Unfortunately, I
need to capture some of the data which was used in the first macro and pass
it along to the 2nd macro.

I've declared the variables "up top" as follows:

Option Explicit
Public xlfile_drive As String
Public period_end As String
Public open_file As String
Public open_file_name As String
Public continueprompt As String

Sub Create_Return_File(xlfile_drive, period_end, open_file, open_file_name,
continueprompt)



periodend = InputBox("Enter reporting month-end in this sample format:
2007-Aug")
xlfile_drive = "T:\mktg\star keystone reporting\Keystone\" & periodend &
"\"
ChDir xlfile_drive
open_file_name = "ROR Series ATC and Models Report-" & Right(periodend,
3) & "-" & Mid(periodend, 3, 2) & ".xls"
open_file = xlfile_drive & open_file_name
...

Further down, I then call the 2nd macro as follows:

Call Add_EPL_Data
...
Public Sub Add_EPL_Data(open_file_name, open_file)
Application.Run "'Personal.xls'!Add_EPL_Returns"
End Sub

Still, the macro is not working and is giving me the error message:

Compile error -- variable not defined.

I had thought, however, that defining it at the global level outside the
subprocedure would resolve this problem?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Passig a variable from one module to another

nice catch. I missed that part of the problem

"JW" wrote:

I haven't examined the workings of your code yet, but you are getting
a Variable Not Defined error because you have a variable named wrong,
which is not allowed when using Option Explicit. You declared
variable period_end with an underscore, but in your code you are using
periodend with no underscore.
Eric_G wrote:
I am attempting to pass a variable value from one module to another module in
another worksheet.

I first collect the values based on user input in macro 1and then call
macro2 from my "PERSONAL.xls" file to continue processing. Unfortunately, I
need to capture some of the data which was used in the first macro and pass
it along to the 2nd macro.

I've declared the variables "up top" as follows:

Option Explicit
Public xlfile_drive As String
Public period_end As String
Public open_file As String
Public open_file_name As String
Public continueprompt As String

Sub Create_Return_File(xlfile_drive, period_end, open_file, open_file_name,
continueprompt)



periodend = InputBox("Enter reporting month-end in this sample format:
2007-Aug")
xlfile_drive = "T:\mktg\star keystone reporting\Keystone\" & periodend &
"\"
ChDir xlfile_drive
open_file_name = "ROR Series ATC and Models Report-" & Right(periodend,
3) & "-" & Mid(periodend, 3, 2) & ".xls"
open_file = xlfile_drive & open_file_name
...

Further down, I then call the 2nd macro as follows:

Call Add_EPL_Data
...
Public Sub Add_EPL_Data(open_file_name, open_file)
Application.Run "'Personal.xls'!Add_EPL_Returns"
End Sub

Still, the macro is not working and is giving me the error message:

Compile error -- variable not defined.

I had thought, however, that defining it at the global level outside the
subprocedure would resolve this problem?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Read Variable from Another Module Mike H. Excel Programming 2 August 27th 07 06:36 PM
STATIC VARIABLE NOT AVAILABLE IN ANOTHER MODULE CAPTGNVR Excel Discussion (Misc queries) 2 February 1st 07 07:30 PM
How to Set a Variable in Another Module? Steve Drenker[_4_] Excel Programming 1 March 17th 06 06:28 PM
Variable in more than one module Nick M[_3_] Excel Programming 2 November 8th 05 07:20 PM
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM


All times are GMT +1. The time now is 12:05 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"