Link to home
Start Free TrialLog in
Avatar of altiplano
altiplano

asked on

How to link an object to a specific Excel sheet

Hi expersts,

I use the following code from the help file:

    OLE1.Class = "Excel.Sheet"
    OLE1.OLETypeAllowed = acOLELinked
    OLE1.SourceDoc = "C:\Excel\Oletext.xls"
    OLE1.SourceItem = "R1C1:R5C5"
    OLE1.Action = acOLECreateLink

This works just fine except that it I can't figure out how to specify a different sheet as SourceItem
I tried several variations on OLE1.SourceItem = "'Sheet 2'!R1C1:R5C5", but nothing seems to work.

Any suggestions?

thanks,
Michiel
Avatar of Glenn_Moore
Glenn_Moore

Why not use a hyperlink?
Did you try:  OLE1.SourceItem = "Sheet 2!R1C1:R5C5"

ie.  Remove the single quotes.
ASKER CERTIFIED SOLUTION
Avatar of GRayL
GRayL
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of altiplano

ASKER

As so often there was a double problem. The quotes were indeed wrong (but the spaces are OK). The other problem however, was the length of the total string. Apparently there is some maximum length of about 50 (?) characters.

So this did not work:
    l_Sheet = "Some rather long sheet name with spaces"
    OLE1.SourceItem = l_Sheet & "!R1C1:R5C5"

but this did:
    l_Sheet = "Short name"
    OLE1.SourceItem = l_Sheet & "!R1C1:R5C5"