|
-
Aug 8th, 2005, 10:50 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Call Excel Sub from VB6
I have a prog that opens up an excel workbook. I am trying to call a sub that is written in the excel workbook (vba) from my vb6 prog.
Is this possible?
Jon_G
AKA Phil From Marketing
**************************************
Insert Something Memorable And Witty Here.
**************************************
-
Aug 8th, 2005, 10:56 PM
#2
Re: Call Excel Sub from VB6
Try calling the Macro (from within Vb6) like:
VB Code:
Call [ExcelObject]Module1.Macro1
-
Aug 8th, 2005, 11:00 PM
#3
Thread Starter
Addicted Member
Re: Call Excel Sub from VB6
so you can call a macro but not a sub on a worksheet?
Jon_G
AKA Phil From Marketing
**************************************
Insert Something Memorable And Witty Here.
**************************************
-
Aug 8th, 2005, 11:08 PM
#4
Re: Call Excel Sub from VB6
Either/Or.
I'm just testing the theory now.
-
Aug 8th, 2005, 11:12 PM
#5
Thread Starter
Addicted Member
Re: Call Excel Sub from VB6
ya i tried that it doesnt wanna work for me
any other suggestions?
Jon_G
AKA Phil From Marketing
**************************************
Insert Something Memorable And Witty Here.
**************************************
-
Aug 8th, 2005, 11:14 PM
#6
Re: Call Excel Sub from VB6
Worked for me:
VB Code:
Call objExcel.Sheets(1).Test_Sub
Please post the code your using open Excel from within VB (I'll mod it to suite)
-
Aug 8th, 2005, 11:16 PM
#7
Thread Starter
Addicted Member
Re: Call Excel Sub from VB6
VB Code:
Private Sub Command1_Click()
Dim myExcelApp As Excel.Application
Dim myExcelSheet As Excel.Worksheet
' Create the Excel application.
Set myExcelApp = New Excel.Application
'open workbook
myExcelApp.Workbooks.Open "C:\Program Files\Iron Test Stand\Graph.xls"
myExcelApp.Visible = True
Set myExcelSheet = Sheets("New Graph")
myExcelSheet.Select
With myExcelApp.ActiveSheet
.txtfilename.Activate
.txtfilename.Text = "C:\Documents and Settings\Jon\Desktop\Iron Tests\2039\123.456-August 08, 2005.csv"
'CALL CMDBROWSW_CLICK()
'The above doesnt work HEEEEEEEEEEELPPPPP lol
End With
End Sub
Jon_G
AKA Phil From Marketing
**************************************
Insert Something Memorable And Witty Here.
**************************************
-
Aug 8th, 2005, 11:31 PM
#8
Re: Call Excel Sub from VB6
Try:
VB Code:
Option Explicit
Private Sub Command1_Click()
Dim myExcelApp As Excel.Application
Dim myExcelSheet As Excel.Worksheet
' Create the Excel application.
Set myExcelApp = New Excel.Application
'open workbook
myExcelApp.Workbooks.Open "C:\Program Files\Iron Test Stand\Graph.xls"
myExcelApp.Visible = True
Set myExcelSheet = Sheets("New Graph")
myExcelSheet.Select
With myExcelApp.ActiveSheet
.txtfilename.Activate
.txtfilename.Text = "C:\Documents and Settings\Jon\Desktop\Iron Tests\2039\123.456-August 08, 2005.csv"
CALL .CMDBROWSW_CLICK()
'Note the . (Dot) preceeding the Sub!
End With
Set myExcelApp = Nothing
End Sub
-
Aug 8th, 2005, 11:33 PM
#9
Re: Call Excel Sub from VB6
I added Option Explicit, and released Memory (by Setin myExcelApp = Nothing)
-
Aug 8th, 2005, 11:46 PM
#10
Thread Starter
Addicted Member
Re: Call Excel Sub from VB6
Lol im retarded
I was calling Private Sub cmdBrowse_Click()
not Public
DOH
Thanks for the help coach! It works great!!!
Jon_G
AKA Phil From Marketing
**************************************
Insert Something Memorable And Witty Here.
**************************************
-
Aug 8th, 2005, 11:53 PM
#11
Re: [RESOLVED] Call Excel Sub from VB6
Great (oops, I forgot to mention that my testSub was Public too..... sorry )
-
Aug 8th, 2005, 11:55 PM
#12
Thread Starter
Addicted Member
Re: [RESOLVED] Call Excel Sub from VB6
Well either way +5 Rep for you 
thanks
Jon_G
AKA Phil From Marketing
**************************************
Insert Something Memorable And Witty Here.
**************************************
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
|