syntax

  • Thread starter Thread starter Don
  • Start date Start date
D

Don

What is the syntax for transfering the value of a varible
in VB6 into VBA, so I can use it in Excel. strQtNum has
been DIM'd in VBA. We can Import Databases, but variables
I do not know.

Thanks.
Don
 
Don said:
What is the syntax for transfering the value of a varible
in VB6 into VBA, so I can use it in Excel. strQtNum has
been DIM'd in VBA. We can Import Databases, but variables
I do not know.

Hi Don,

Two ways I can think of right off the bat.

1) Have your VB6 DLL or EXE write the value of the variable to a known cell
in a worksheet of an open workbook on the Excel side and then have VBA read
the value of the variable from that cell.

2) If you have a class within your VB6 DLL or EXE that VBA has a reference
to, add a Property procedure to that class that returns the value of the
variable. Then have VBA call that property of the class to retrieve the
variable's value.

If you'd like more detail on how to implement either of these methods,
post back with a bit more detail on exactly what the relationship is between
Excel and VB6 in your project and I'll be glad to help you out.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *
 
Variables in VBA follow the same scope and lifetime restrictions as
variables in VB6. So you couldn't create a variable in Excel unless you use
the VBA extensibility library and declared it, then wrote code to initialize
it and executed the code.

Perhaps there is a workaround if you could be more specific about what you
want to do. Are you trying to run a macro and to pass it a variable value.

in a VBA General Module

Public gMyVar as Long

Public Sub SetMyVar(myVal)
gMyVar = myVal
End Sub

Public Function MyVar()
Application.Volatile
myVar = gMyVar
End Sub

in VB6

someVar = 21
xlApp.Run "MyWorkbook.xls!SetMyVar", someVar


A worksheet could use a formula

=Sum(A1:B9,MyVar())
 
Back
Top