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
altiplanoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

ie.  Remove the single quotes.
0
GRayLCommented:
Sorry and remove the space:

OLE1.SourceItem = "Sheet2!R1C1:R5C5"

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
altiplanoAuthor Commented:
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"
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.