Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • 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
Joined
Jun 21, 2006
Messages
15,161
Location
GB
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)
***************
 
Lift your skirt and show us your code.
 
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

Back
Top