Kind of a stupid question. Is it possible to create/embed an excel
spreadsheet into a word document with VBA?

I can just create a regular table and then copy and paste to Excel,
but I want to know if there is any better option.

Re: Creating Excel Spreadsheet in Word with VBA by Jay

Jay
Fri Feb 22 10:56:18 PST 2008

On Fri, 22 Feb 2008 10:13:24 -0800 (PST), melon <elty123@gmail.com> wrote:

>Kind of a stupid question. Is it possible to create/embed an excel
>spreadsheet into a word document with VBA?
>
>I can just create a regular table and then copy and paste to Excel,
>but I want to know if there is any better option.

You can use VBA syntax like this:

Selection.InlineShapes.AddOLEObject FileName:="C:\SomeFolder\book1.xls"

There are lots of variations on this.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.

Re: Creating Excel Spreadsheet in Word with VBA by melon

melon
Fri Feb 22 12:27:03 PST 2008

I got an error with this (type mismatch)

objWord.ActiveDocument.Bookmarks("Required").Range.InlineShapes.AddOLEControl
ClassType:="Excel.Sheet"

What cause that?

Re: Creating Excel Spreadsheet in Word with VBA by melon

melon
Fri Feb 22 12:32:17 PST 2008

On Feb 22, 3:27 pm, melon <elty...@gmail.com> wrote:
> I got an error with this (type mismatch)
>
> objWord.ActiveDocument.Bookmarks("Required").Range.InlineShapes.AddOLEControl
> ClassType:="Excel.Sheet"
>
> What cause that?

I don't think the syntax is incorrect, since if I change the ClassType
to something like "Forms.ComboBox.1" then it works.

Re: Creating Excel Spreadsheet in Word with VBA by Jay

Jay
Fri Feb 22 16:26:04 PST 2008

On Fri, 22 Feb 2008 12:32:17 -0800 (PST), melon <elty123@gmail.com> wrote:

>On Feb 22, 3:27 pm, melon <elty...@gmail.com> wrote:
>> I got an error with this (type mismatch)
>>
>> objWord.ActiveDocument.Bookmarks("Required").Range.InlineShapes.AddOLEControl
>> ClassType:="Excel.Sheet"
>>
>> What cause that?
>
>I don't think the syntax is incorrect, since if I change the ClassType
>to something like "Forms.ComboBox.1" then it works.

I don't know why that doesn't work -- the documentation says it should be OK --
but I get the same error.

Instead of the AddOLEControl method, use the AddOLEObject method (which is what
I showed in my first response). I found that does work.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.

Re: Creating Excel Spreadsheet in Word with VBA by Peter

Peter
Mon Feb 25 09:29:20 PST 2008

FWIW I think the immediate reason is that the Excel.Sheet is not defined to
be a "Control" (if you look in the registry for Forms.ComboBox.1 and find
the entry for its CLSID, it has a Key called "Control" under it. If you
experimentally add one under the CLSID for "Excel.Sheet", restart Word and
try again, Word will go to the next stage and fail with a memoory-related
message, presumably because the object does not actually implement whatever
interfaces it needs to be a "Control".

--
Peter Jamieson
http://tips.pjmsn.me.uk

"Jay Freedman" <jay.freedman@verizon.net> wrote in message
news:eopur35b2vr35oiooqtda2if28q1ekje2c@4ax.com...
> On Fri, 22 Feb 2008 12:32:17 -0800 (PST), melon <elty123@gmail.com> wrote:
>
>>On Feb 22, 3:27 pm, melon <elty...@gmail.com> wrote:
>>> I got an error with this (type mismatch)
>>>
>>> objWord.ActiveDocument.Bookmarks("Required").Range.InlineShapes.AddOLEControl
>>> ClassType:="Excel.Sheet"
>>>
>>> What cause that?
>>
>>I don't think the syntax is incorrect, since if I change the ClassType
>>to something like "Forms.ComboBox.1" then it works.
>
> I don't know why that doesn't work -- the documentation says it should be
> OK --
> but I get the same error.
>
> Instead of the AddOLEControl method, use the AddOLEObject method (which is
> what
> I showed in my first response). I found that does work.
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup
> so all may benefit.


Re: Creating Excel Spreadsheet in Word with VBA by Jay

Jay
Mon Feb 25 09:42:41 PST 2008

I think you're correct, but the MS help (and MSDN) don't qualify the
ClassType values that way. If you go to the topic on AddOLEControl and then
follow the link in that topic to the one on OLE Programmatic Identifiers
(http://msdn2.microsoft.com/en-us/library/aa200268(office.10).aspx ),
Excel.Sheet appears to be a valid choice.

Peter Jamieson wrote:
> FWIW I think the immediate reason is that the Excel.Sheet is not
> defined to be a "Control" (if you look in the registry for
> Forms.ComboBox.1 and find the entry for its CLSID, it has a Key
> called "Control" under it. If you experimentally add one under the
> CLSID for "Excel.Sheet", restart Word and try again, Word will go to
> the next stage and fail with a memoory-related message, presumably
> because the object does not actually implement whatever interfaces it
> needs to be a "Control".
>
> "Jay Freedman" <jay.freedman@verizon.net> wrote in message
> news:eopur35b2vr35oiooqtda2if28q1ekje2c@4ax.com...
>> On Fri, 22 Feb 2008 12:32:17 -0800 (PST), melon <elty123@gmail.com>
>> wrote:
>>> On Feb 22, 3:27 pm, melon <elty...@gmail.com> wrote:
>>>> I got an error with this (type mismatch)
>>>>
>>>> objWord.ActiveDocument.Bookmarks("Required").Range.InlineShapes.AddOLEControl
>>>> ClassType:="Excel.Sheet"
>>>>
>>>> What cause that?
>>>
>>> I don't think the syntax is incorrect, since if I change the
>>> ClassType to something like "Forms.ComboBox.1" then it works.
>>
>> I don't know why that doesn't work -- the documentation says it
>> should be OK --
>> but I get the same error.
>>
>> Instead of the AddOLEControl method, use the AddOLEObject method
>> (which is what
>> I showed in my first response). I found that does work.
>>
>> --
>> Regards,
>> Jay Freedman
>> Microsoft Word MVP FAQ: http://word.mvps.org
>> Email cannot be acknowledged; please post all follow-ups to the
>> newsgroup so all may benefit.



Re: Creating Excel Spreadsheet in Word with VBA by Peter

Peter
Tue Feb 26 01:59:43 PST 2008

Agreed.

--
Peter Jamieson
http://tips.pjmsn.me.uk

"Jay Freedman" <jay.freedman@verizon.net> wrote in message
news:uMoYTX9dIHA.4396@TK2MSFTNGP02.phx.gbl...
>I think you're correct, but the MS help (and MSDN) don't qualify the
>ClassType values that way. If you go to the topic on AddOLEControl and then
>follow the link in that topic to the one on OLE Programmatic Identifiers
>(http://msdn2.microsoft.com/en-us/library/aa200268(office.10).aspx ),
>Excel.Sheet appears to be a valid choice.
>
> Peter Jamieson wrote:
>> FWIW I think the immediate reason is that the Excel.Sheet is not
>> defined to be a "Control" (if you look in the registry for
>> Forms.ComboBox.1 and find the entry for its CLSID, it has a Key
>> called "Control" under it. If you experimentally add one under the
>> CLSID for "Excel.Sheet", restart Word and try again, Word will go to
>> the next stage and fail with a memoory-related message, presumably
>> because the object does not actually implement whatever interfaces it
>> needs to be a "Control".
>>
>> "Jay Freedman" <jay.freedman@verizon.net> wrote in message
>> news:eopur35b2vr35oiooqtda2if28q1ekje2c@4ax.com...
>>> On Fri, 22 Feb 2008 12:32:17 -0800 (PST), melon <elty123@gmail.com>
>>> wrote:
>>>> On Feb 22, 3:27 pm, melon <elty...@gmail.com> wrote:
>>>>> I got an error with this (type mismatch)
>>>>>
>>>>> objWord.ActiveDocument.Bookmarks("Required").Range.InlineShapes.AddOLEControl
>>>>> ClassType:="Excel.Sheet"
>>>>>
>>>>> What cause that?
>>>>
>>>> I don't think the syntax is incorrect, since if I change the
>>>> ClassType to something like "Forms.ComboBox.1" then it works.
>>>
>>> I don't know why that doesn't work -- the documentation says it
>>> should be OK --
>>> but I get the same error.
>>>
>>> Instead of the AddOLEControl method, use the AddOLEObject method
>>> (which is what
>>> I showed in my first response). I found that does work.
>>>
>>> --
>>> Regards,
>>> Jay Freedman
>>> Microsoft Word MVP FAQ: http://word.mvps.org
>>> Email cannot be acknowledged; please post all follow-ups to the
>>> newsgroup so all may benefit.
>
>