Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing Excel.Applications to VB6 subroutines

Status
Not open for further replies.

BigInch

Petroleum
Jun 21, 2006
15,161
I'm trying to use early binding of an Excel.Application in VB6, then do some operations in subroutines, but references to the Application's properties when in the subs return nothing. I assume its a problem passing the application, byref, byvalue, as object, or by something into the subroutines that I don't understand. Anybody got any ideas on how2?

"Make everything as simple as possible, but not simpler." - Albert Einstein (1879-1955)
***************
 
Replies continue below

Recommended for you

Hey THANKS Tick!

When I was writing this example code to show you... it worked! Before I was trying to pass XLApp. This time I tried just passing the worksheet XLWkSht.

If ExcelExists = False Then Exit Sub
Dim XLApp As Excel.Application
Dim XLWkBk As Excel.Workbook
Dim XLWkSht As Excel.Worksheet

If ExcelRuns = False Then _
Set XLApp = New Excel.Application
Set XLApp = GetObject(, "Excel.Application")
XLApp.Visible = True
Set XLWkBk = XLApp.Workbooks(WBindex)
XLApp.Workbooks(WBindex).Activate
Set XLWkSht = XLWkBk.Sheets(1)
XLWkBk.Sheets(1).Activate
WriteValues XLWkSht
End Sub

Public Sub WriteValues(XLWkSht)

XLWkSht.Cells(26, 2) = "FLOW"
XLWkSht.Cells(26, 3) = "HEAD"
XLWkSht.Cells(26, 4) = "EFF"
XLWkSht.Cells(26, 5) = "POWER"

End Sub


"Make everything as simple as possible, but not simpler." - Albert Einstein (1879-1955)
***************
 
But, but, but ... I still can't do something like this,

Public Sub Look4WkBk(XLApp, File_Name)
For i = 1 To XLApp.Workbooks.Count
If File_Name = _
XLApp.Workbooks(i).Path & "\" & _
XLApp.Workbooks(i).Name Then
XLApp.Workbooks(i).Activate
Exit For
End If
Next i
End Sub


"Make everything as simple as possible, but not simpler." - Albert Einstein (1879-1955)
***************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor