|
-
Oct 24th, 2005, 05:28 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Run Excel Module code from Access...
I am opening an excel spreadsheet from Access called test.xls like below. I have a Sub saved in the spreadsheet in Module1 called Test.
How do I run that from Access???
VB Code:
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlWSheet As Excel.Worksheet
Set xlApp = New Excel.Application
xlApp.Workbooks.Open ("C:\Test.xls")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks(1)
Set xlWSheet = xlApp.Worksheets(1)
'call xlapp.module1.test ????????
xlBook.Module1.test
Last edited by strobinson1; Oct 25th, 2005 at 03:28 AM.
-
Oct 24th, 2005, 05:55 AM
#2
Thread Starter
Addicted Member
Re: Run Excel Module code from Access...
ok,
sorted that one with
Call xlApp.Run("mdltest.test")
Any ideas on how to update Excel variables from Access??
-
Oct 24th, 2005, 07:00 AM
#3
Re: Run Excel Module code from Access...
The variables are running in separate processes, and therefore cannot be updated directly.
I would recommend making subs in Excel which can update them for you, eg:
VB Code:
Public Sub UpdateVar_Fred (NewValue as Integer)
Fred = NewValue
End Sub
..hopefully you can call it like this:
Call xlApp.Run("mdltest.UpdateVar_Fred 4")
-
Oct 24th, 2005, 09:28 AM
#4
Thread Starter
Addicted Member
Re: Run Excel Module code from Access...
I've actually done it by copying my Access variable data to a cell on the spreadsheet and then in the excel code updating the excel variable by looking at that cell, and finally emptying the cell.
Will try your method now.
Is there a way to send data the other way aswell?? ie the Err value should the process fail in excel, i want to store the Err value in Access.....???
-
Oct 24th, 2005, 09:38 AM
#5
Thread Starter
Addicted Member
Re: Run Excel Module code from Access...
Used syntax like this in Access to send Access Variable to Excel Function:
VB Code:
xlApp.Run "test", strName
Still need to work out how to return a value back to Access from Excel....?????
Last edited by strobinson1; Oct 24th, 2005 at 10:57 AM.
-
Oct 24th, 2005, 11:16 AM
#6
Re: Run Excel Module code from Access...
I would assume that Run itself is a function, and returns the value from the function that you call. If that is true, the following should work:
myVar = xlApp.Run ("test", strName)
Note that if the parameters (like strName above) are defined as ByRef you may be able to alter them in the function/sub and then read them on return to the caller program.
-
Oct 25th, 2005, 03:27 AM
#7
Thread Starter
Addicted Member
Re: Run Excel Module code from Access...
Yup...that's exactly how i did it!!
Cheers!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|