PDA

View Full Version : Trying to write to embedded OLE Excel sheet in VB6



dc4life78
02-20-2009, 08:36 PM
Hey everyone,

I have created four embedded OLE Excel objects within my form and am trying to write data to them, but I cannot seem to access any of them. I have never used OLE objects so I'm at a loss at where to start beyond what I have so far which I have seen on various occasions in other forums:

Dim ctl As Control
Dim wks As Excel.Worksheet

Set ctl = Me.OLE1
Set wks = ctl.Object.Application.Workbooks(1).Worksheets(1)

If the Set command line worked correctly I would be go to go and simply proceed with Cells(X,Y).Value or Range("XX").Value. But this does not execute; I get an error message saying Object variable not set. What am I missing?

Thanks in advance for your help!

dc4life78
02-25-2009, 09:50 AM
I was able to get the code to work - for others who may have the same problem here is the solution:
Dim oOLE As Object
Dim oSheet As Object

Set oOLE = Me.OLE1.object
Set oSheet = oOLE.Sheet(1)

From here you can use oSheet.Range("XX")... to manipulate the cells as desired.