Consulting

Results 1 to 2 of 2

Thread: Trying to write to embedded OLE Excel sheet in VB6

  1. #1

    Trying to write to embedded OLE Excel sheet in VB6

    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:

    [VBA]Dim ctl As Control
    Dim wks As Excel.Worksheet

    Set ctl = Me.OLE1
    Set wks = ctl.Object.Application.Workbooks(1).Worksheets(1)[/VBA]

    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!

  2. #2
    I was able to get the code to work - for others who may have the same problem here is the solution:
    [vba]Dim oOLE As Object
    Dim oSheet As Object

    Set oOLE = Me.OLE1.object
    Set oSheet = oOLE.Sheet(1)[/vba]

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •