Visual Studio Developer Center >
Visual Studio Forums
>
Visual Studio Tools for Office
>
how to use OLEFormat.Object
how to use OLEFormat.Object
- Hi.I'm using vsto3 on excel2003. I add a webbrowser control to sheet by code: AddOLEObject("Shell.Explorer.2",.....);But the question is that i have no idea how to bind "OLEFormat.Object" to the webbrowser to do "navigate".I try WebBrowser.FromHandle, but does not work.Can any guy solve the problem? Thank.ps: I found OLEFormat.Object is really mysterious, little stuff illustrate it.
Answers
- Hi Sheng Hao
We may not be able to assist you with this, as the question isn't really about VSTO, but about how to access the exposed OLE interface of the object you're inserting. The COM OLE interface can only give you access to what the OLE Server (the web browser control) exposes, and I have no idea what those commands might be.
The syntax to be used depends on the programming language involved. Most of the work I've done with OLE servers (Excel object embedded in Word documents, for the most part) as been with a VB language. So my explanation, with pseudo-code, will base on that.
The OleFormat.Object property should return the basic object represented by the embedded object. In the case of Excel, that will be an Excel.Workbook, or an Excel.Chart. If I'm unsure what this is, I'll usually resort to VBA and do something like this:
Dim o as Object
Set o = theEmbeddedObject.OLEFormat.Object
Debug.Print o.Parent, o.Name
As most objects have a Parent and a Name property, this gives me an idea what I'm dealing with. The information will appear in the VBA Editor's Immediate Window (Ctrl+G to toggle on/off). And since VB(A) is weakly-typed, no worries about casting, etc.
When I test your object (in Word), I get: "Document1" "Microsoft Web Browser Control"
So the next thing I do is look in Tools/References for a Type library that matches this OLE Class. This appears to be ieframe.dll. At least, when I activate a reference to it, the following works without giving me an error (Although I can't see the object in the Word document as anything but an empty box):
Dim wb As WebBrowser
Set wb = ActiveDocument.InlineShapes(1).OLEFormat.Object
wb.Visible = True
wb.AddressBar = True
wb.GoHome
wb.Navigate2 "www.microsoft.com"
I hope this is enough to get you started, but as I mentioned, it's not really on-topic here...
Cindy Meister, VSTO/Word MVP- Marked As Answer bysheng hao Wednesday, November 11, 2009 1:54 AM
All Replies
- Hi Sheng Hao
We may not be able to assist you with this, as the question isn't really about VSTO, but about how to access the exposed OLE interface of the object you're inserting. The COM OLE interface can only give you access to what the OLE Server (the web browser control) exposes, and I have no idea what those commands might be.
The syntax to be used depends on the programming language involved. Most of the work I've done with OLE servers (Excel object embedded in Word documents, for the most part) as been with a VB language. So my explanation, with pseudo-code, will base on that.
The OleFormat.Object property should return the basic object represented by the embedded object. In the case of Excel, that will be an Excel.Workbook, or an Excel.Chart. If I'm unsure what this is, I'll usually resort to VBA and do something like this:
Dim o as Object
Set o = theEmbeddedObject.OLEFormat.Object
Debug.Print o.Parent, o.Name
As most objects have a Parent and a Name property, this gives me an idea what I'm dealing with. The information will appear in the VBA Editor's Immediate Window (Ctrl+G to toggle on/off). And since VB(A) is weakly-typed, no worries about casting, etc.
When I test your object (in Word), I get: "Document1" "Microsoft Web Browser Control"
So the next thing I do is look in Tools/References for a Type library that matches this OLE Class. This appears to be ieframe.dll. At least, when I activate a reference to it, the following works without giving me an error (Although I can't see the object in the Word document as anything but an empty box):
Dim wb As WebBrowser
Set wb = ActiveDocument.InlineShapes(1).OLEFormat.Object
wb.Visible = True
wb.AddressBar = True
wb.GoHome
wb.Navigate2 "www.microsoft.com"
I hope this is enough to get you started, but as I mentioned, it's not really on-topic here...
Cindy Meister, VSTO/Word MVP- Marked As Answer bysheng hao Wednesday, November 11, 2009 1:54 AM
- Hi, Cindy Meister:
Thanks for your method. The way you offer is really useful .
If I posted wrong place, I'm sorry.
Thanks again.
sheng hao.


