DJWheezyWeez
Technical User
Hi,
I've been using Dim x as String variables and I've been playing around with Public instead and I'm having a problem making one work.
In my testing, I've gotten this to work starting from a brand new book with two brand new modules:
Module1:
Public testVar As String
Sub testone()
testVar = "testing testing one two"
End Sub
Module2:
Sub testtwo()
ActiveCell.FormulaR1C1 = testVar
End Sub
When I run the testtwo macro, it fills in "testing testing one two" into the currently active cell. My next attempt at playing around is dealing with opening an existing workbook (as part of a much larger macro).
In my testing, again with a brand new workbook and two new modules, this is what I have but it's not working:
Module1:
Public filePath As String
Sub fpone()
filePath = "W:\IT\Zach\Sales Journal\Testing\"
End Sub
Module2:
Sub fptwo()
Workbooks.Open Filename:=filePath & "Files\Toms_Variance_Setup.xlsm"
End Sub
This time, when I run the fptwo macro, I get an error saying it can't find the 'Files\Toms_Variance_Setup.xlsm' file since it's not using the filePath variable string in the file path. the fptwo macro DOES work if I put the filePath variable inside it instead of fpone.
I'm wondering why does this work in my first example but not the second?
Will this work with some tweaking or is this just not possible?
-DJWW
I've been using Dim x as String variables and I've been playing around with Public instead and I'm having a problem making one work.
In my testing, I've gotten this to work starting from a brand new book with two brand new modules:
Module1:
Public testVar As String
Sub testone()
testVar = "testing testing one two"
End Sub
Module2:
Sub testtwo()
ActiveCell.FormulaR1C1 = testVar
End Sub
When I run the testtwo macro, it fills in "testing testing one two" into the currently active cell. My next attempt at playing around is dealing with opening an existing workbook (as part of a much larger macro).
In my testing, again with a brand new workbook and two new modules, this is what I have but it's not working:
Module1:
Public filePath As String
Sub fpone()
filePath = "W:\IT\Zach\Sales Journal\Testing\"
End Sub
Module2:
Sub fptwo()
Workbooks.Open Filename:=filePath & "Files\Toms_Variance_Setup.xlsm"
End Sub
This time, when I run the fptwo macro, I get an error saying it can't find the 'Files\Toms_Variance_Setup.xlsm' file since it's not using the filePath variable string in the file path. the fptwo macro DOES work if I put the filePath variable inside it instead of fpone.
I'm wondering why does this work in my first example but not the second?
Will this work with some tweaking or is this just not possible?
-DJWW