RE: Word Document that shows Excel Chart

Discussion in 'Microsoft Excel Programming' started by Peter Huang [MSFT], Aug 22, 2003.

  1. Hi

    Here is a sample code.
    [Here the book2.xls located on c: have a chart on sheet1]

    Private Sub Command2_Click()
    Dim wd As Word.Application
    Dim exapp As Excel.Application
    Set wd = New Word.Application
    Set exapp = New Excel.Application
    exapp.Workbooks.Open "c:\book2.xls"
    exapp.Worksheets("Sheet1").ChartObjects(1).Chart.ChartArea.Copy
    wd.Visible = True
    wd.Documents.Add.Content.PasteSpecial link:=True, DataType:=0
    End Sub

    Please have a try and let me if this does the job for you.
    Regards,
    Peter Huang
    Microsoft Online Partner Support
    Get Secure! www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.

    --------------------
    >From: "hmmm..." <>
    >Newsgroups:

    microsoft.public.word.oleinterop,microsoft.public.word.vba.general,microsoft
    public.word.word97vba,microsoft.public.excel.charting,microsoft.public.exce
    l.misc,microsoft.public.excel.programming
    >Subject: Word Document that shows Excel Chart
    >Lines: 8
    >X-Priority: 3
    >X-MSMail-Priority: Normal
    >X-Newsreader: Microsoft Outlook Express 5.50.4807.1700
    >X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    >Message-ID: <Q6O0b.1018$>
    >Date: Wed, 20 Aug 2003 17:21:52 GMT
    >NNTP-Posting-Host: 209.178.190.87
    >X-Complaints-To:
    >X-Trace: newsread4.news.pas.earthlink.net 1061400112 209.178.190.87 (Wed,

    20 Aug 2003 10:21:52 PDT)
    >NNTP-Posting-Date: Wed, 20 Aug 2003 10:21:52 PDT
    >Organization: EarthLink Inc. -- http://www.EarthLink.net
    >Path:

    cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
    e.de!newsfeed.freenet.de!newsfeed.news2me.com!elnk-nf2-pas!newsfeed.earthlin
    k.net!stamper.news.pas.earthlink.net!newsread4.news.pas.earthlink.net.POSTED
    !not-for-mail
    >Xref: cpmsftngxa06.phx.gbl microsoft.public.word.vba.general:41111

    microsoft.public.word.word97vba:68352 microsoft.public.excel.charting:32887
    microsoft.public.excel.misc:266349
    microsoft.public.excel.programming:408492
    microsoft.public.word.oleinterop:8588
    >X-Tomcat-NG: microsoft.public.excel.programming
    >
    >I would like to launch an Excel workbook from a Word document. The

    workbook
    >updates a chart when the workbook is started. The chart must be displayed
    >in the Word document.Can anyone point me in the right direction, or show me
    >an example piece of code?
    >
    >Thanks.
    >
    >
    >
     
    Peter Huang [MSFT], Aug 22, 2003
    #1
    1. Advertisements

  2. Peter Huang [MSFT]

    hmmm... Guest

    I had a problem with your example. I get a compile error at "Dim exapp As
    Excel.Application".

    Compile error:
    User-defined type not defined

    Do you know why?

    Also, is your command button in a Word document or and Excel workbook? I
    want the end user to open up a Word document. The button should be in the
    Word document and should cause the Excel chart to appear in a predetermined
    place. It looks like your example creates a new Word document and displays
    the chart in that document. I don't think that will work for me.

    Thanks.

    "Peter Huang [MSFT]" <> wrote in message
    news:...
    > Hi
    >
    > Here is a sample code.
    > [Here the book2.xls located on c: have a chart on sheet1]
    >
    > Private Sub Command2_Click()
    > Dim wd As Word.Application
    > Dim exapp As Excel.Application
    > Set wd = New Word.Application
    > Set exapp = New Excel.Application
    > exapp.Workbooks.Open "c:\book2.xls"
    > exapp.Worksheets("Sheet1").ChartObjects(1).Chart.ChartArea.Copy
    > wd.Visible = True
    > wd.Documents.Add.Content.PasteSpecial link:=True, DataType:=0
    > End Sub
    >
    > Please have a try and let me if this does the job for you.
    > Regards,
    > Peter Huang
    > Microsoft Online Partner Support
    > Get Secure! www.microsoft.com/security
    > This posting is provided "as is" with no warranties and confers no rights.
    >
    > --------------------
    > >From: "hmmm..." <>
    > >Newsgroups:

    >

    microsoft.public.word.oleinterop,microsoft.public.word.vba.general,microsoft
    >

    ..public.word.word97vba,microsoft.public.excel.charting,microsoft.public.exce
    > l.misc,microsoft.public.excel.programming
    > >Subject: Word Document that shows Excel Chart
    > >Lines: 8
    > >X-Priority: 3
    > >X-MSMail-Priority: Normal
    > >X-Newsreader: Microsoft Outlook Express 5.50.4807.1700
    > >X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    > >Message-ID: <Q6O0b.1018$>
    > >Date: Wed, 20 Aug 2003 17:21:52 GMT
    > >NNTP-Posting-Host: 209.178.190.87
    > >X-Complaints-To:
    > >X-Trace: newsread4.news.pas.earthlink.net 1061400112 209.178.190.87 (Wed,

    > 20 Aug 2003 10:21:52 PDT)
    > >NNTP-Posting-Date: Wed, 20 Aug 2003 10:21:52 PDT
    > >Organization: EarthLink Inc. -- http://www.EarthLink.net
    > >Path:

    >

    cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
    >

    e.de!newsfeed.freenet.de!newsfeed.news2me.com!elnk-nf2-pas!newsfeed.earthlin
    >

    k.net!stamper.news.pas.earthlink.net!newsread4.news.pas.earthlink.net.POSTED
    > !not-for-mail
    > >Xref: cpmsftngxa06.phx.gbl microsoft.public.word.vba.general:41111

    > microsoft.public.word.word97vba:68352

    microsoft.public.excel.charting:32887
    > microsoft.public.excel.misc:266349
    > microsoft.public.excel.programming:408492
    > microsoft.public.word.oleinterop:8588
    > >X-Tomcat-NG: microsoft.public.excel.programming
    > >
    > >I would like to launch an Excel workbook from a Word document. The

    > workbook
    > >updates a chart when the workbook is started. The chart must be

    displayed
    > >in the Word document.Can anyone point me in the right direction, or show

    me
    > >an example piece of code?
    > >
    > >Thanks.
    > >
    > >
    > >

    >
    >
    >
    >
     
    hmmm..., Aug 25, 2003
    #2
    1. Advertisements

  3. Hi,

    >I had a problem with your example. I get a compile error at "Dim exapp As
    >Excel.Application".
    >
    >Compile error:
    >User-defined type not defined
    >
    >Do you know why?
    >


    It seems that you have not make reference to the Microsoft Excel Object
    Library. You may do that by following the steps below.
    1. Open the word application and Press Alt +F11, this will open Visual
    Basic for Editor.
    2. Select Tool/reference menu and check the Microsoft Excel 10.0 Object
    Library<because mine is office 2002, so the version is 10.0>
    3. Copy and paste the code below to the Editor
    Sub test()
    Dim exapp As Excel.Application
    Set exapp = New Excel.Application
    exapp.Workbooks.Open "c:\book2.xls" 'you may need to establish a book2.xls
    first, which include a chart in sheet1
    exapp.Worksheets("Sheet1").ChartObjects(1).Chart.ChartArea.Copy
    Application.ActiveDocument.Content.PasteSpecial Link:=True,
    DataType:=wdPasteOLEObject
    exapp.quit
    set exapp = Nothing
    End Sub
    4. Press F5 to run the macro.

    You may have a try and let me know if this does the job for you.

    >Also, is your command button in a Word document or and Excel workbook? I
    >want the end user to open up a Word document. The button should be in the
    >Word document and should cause the Excel chart to appear in a predetermined
    >place. It looks like your example creates a new Word document and displays
    >the chart in that document. I don't think that will work for me.


    I create the sample code in VB6 not in the VBA editor of word, I am sorry
    for confusion. You may refer to code above , when you run the macro above
    will insert an excel chart object as a OLE object into word.

    Regards,
    Peter Huang
    Microsoft Online Partner Support
    Get Secure! www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    --------------------
    >From: "hmmm..." <>
    >Newsgroups:

    microsoft.public.excel.programming,microsoft.public.word.oleinterop,microsof
    t.public.word.vba.general,microsoft.public.word.word97vba,microsoft.public.e
    xcel.charting,microsoft.public.excel.misc
    >References: <Q6O0b.1018$>

    <>
    >Subject: Re: Word Document that shows Excel Chart
    >Lines: 97
    >X-Priority: 3
    >X-MSMail-Priority: Normal
    >X-Newsreader: Microsoft Outlook Express 5.50.4922.1500
    >X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4925.2800
    >Message-ID: <Uar2b.2643$>
    >Date: Mon, 25 Aug 2003 16:54:12 GMT
    >NNTP-Posting-Host: 209.179.228.32
    >X-Complaints-To:
    >X-Trace: newsread4.news.pas.earthlink.net 1061830452 209.179.228.32 (Mon,

    25 Aug 2003 09:54:12 PDT)
    >NNTP-Posting-Date: Mon, 25 Aug 2003 09:54:12 PDT
    >Organization: EarthLink Inc. -- http://www.EarthLink.net
    >Path:

    cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
    e.de!nntp-relay.ihug.net!ihug.co.nz!logbridge.uoregon.edu!newshub.sdsu.edu!e
    lnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread4.
    news.pas.earthlink.net.POSTED!not-for-mail
    >Xref: cpmsftngxa06.phx.gbl microsoft.public.word.oleinterop:8611

    microsoft.public.word.vba.general:41322
    microsoft.public.word.word97vba:68370 microsoft.public.excel.charting:33006
    microsoft.public.excel.misc:267255 microsoft.public.excel.programming:409816
    >X-Tomcat-NG: microsoft.public.excel.programming
    >
    >I had a problem with your example. I get a compile error at "Dim exapp As
    >Excel.Application".
    >
    >Compile error:
    >User-defined type not defined
    >
    >Do you know why?
    >
    >Also, is your command button in a Word document or and Excel workbook? I
    >want the end user to open up a Word document. The button should be in the
    >Word document and should cause the Excel chart to appear in a predetermined
    >place. It looks like your example creates a new Word document and displays
    >the chart in that document. I don't think that will work for me.
    >
    >Thanks.
    >
    >"Peter Huang [MSFT]" <> wrote in message
    >news:...
    >> Hi
    >>
    >> Here is a sample code.
    >> [Here the book2.xls located on c: have a chart on sheet1]
    >>
    >> Private Sub Command2_Click()
    >> Dim wd As Word.Application
    >> Dim exapp As Excel.Application
    >> Set wd = New Word.Application
    >> Set exapp = New Excel.Application
    >> exapp.Workbooks.Open "c:\book2.xls"
    >> exapp.Worksheets("Sheet1").ChartObjects(1).Chart.ChartArea.Copy
    >> wd.Visible = True
    >> wd.Documents.Add.Content.PasteSpecial link:=True, DataType:=0
    >> End Sub
    >>
    >> Please have a try and let me if this does the job for you.
    >> Regards,
    >> Peter Huang
    >> Microsoft Online Partner Support
    >> Get Secure! www.microsoft.com/security
    >> This posting is provided "as is" with no warranties and confers no

    rights.
    >>
    >> --------------------
    >> >From: "hmmm..." <>
    >> >Newsgroups:

    >>

    >microsoft.public.word.oleinterop,microsoft.public.word.vba.general,microsof

    t
    >>

    >.public.word.word97vba,microsoft.public.excel.charting,microsoft.public.exc

    e
    >> l.misc,microsoft.public.excel.programming
    >> >Subject: Word Document that shows Excel Chart
    >> >Lines: 8
    >> >X-Priority: 3
    >> >X-MSMail-Priority: Normal
    >> >X-Newsreader: Microsoft Outlook Express 5.50.4807.1700
    >> >X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    >> >Message-ID: <Q6O0b.1018$>
    >> >Date: Wed, 20 Aug 2003 17:21:52 GMT
    >> >NNTP-Posting-Host: 209.178.190.87
    >> >X-Complaints-To:
    >> >X-Trace: newsread4.news.pas.earthlink.net 1061400112 209.178.190.87

    (Wed,
    >> 20 Aug 2003 10:21:52 PDT)
    >> >NNTP-Posting-Date: Wed, 20 Aug 2003 10:21:52 PDT
    >> >Organization: EarthLink Inc. -- http://www.EarthLink.net
    >> >Path:

    >>

    >cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onli

    n
    >>

    >e.de!newsfeed.freenet.de!newsfeed.news2me.com!elnk-nf2-pas!newsfeed.earthli

    n
    >>

    >k.net!stamper.news.pas.earthlink.net!newsread4.news.pas.earthlink.net.POSTE

    D
    >> !not-for-mail
    >> >Xref: cpmsftngxa06.phx.gbl microsoft.public.word.vba.general:41111

    >> microsoft.public.word.word97vba:68352

    >microsoft.public.excel.charting:32887
    >> microsoft.public.excel.misc:266349
    >> microsoft.public.excel.programming:408492
    >> microsoft.public.word.oleinterop:8588
    >> >X-Tomcat-NG: microsoft.public.excel.programming
    >> >
    >> >I would like to launch an Excel workbook from a Word document. The

    >> workbook
    >> >updates a chart when the workbook is started. The chart must be

    >displayed
    >> >in the Word document.Can anyone point me in the right direction, or show

    >me
    >> >an example piece of code?
    >> >
    >> >Thanks.
    >> >
    >> >
    >> >

    >>
    >>
    >>
    >>

    >
    >
    >
     
    Peter Huang [MSFT], Aug 26, 2003
    #3
  4. Hi

    >1. What must I do to get the Excel application to understand the calls to
    >the DDE server when opened from the Word application?


    To isolate the problem, I want to collect some information.
    1. What error message do you get in your "real" Excel application?
    2. You may try to set the exapp.visible to true to see if the problem
    persists.
    e.g.
    Sub test()
    Dim exapp As Excel.Application
    Set exapp = New Excel.Application
    Exapp.visible = true
    exapp.Workbooks.Open "c:\book2.xls" 'you may need to establish a book2.xls
    exapp.Worksheets("Sheet1").ChartObjects(1).Chart.ChartArea.Copy
    Application.ActiveDocument.Content.PasteSpecial Link:=True,
    DataType:=wdPasteOLEObject
    exapp.ActiveWorkbook.Saved = True
    exapp.Quit
    Set exapp = Nothing
    End Sub
    3. You may try to open the excel application and then open the workbook by
    automation, and then call the macro that will retrieve data from DDE.
    e.g. exapp.Run "a.xls!testmacro" ' the testmacro is one module macro in
    the a.xls file.



    >2. From the Word application, how do I position the Excel chart at a
    >certain place on a certain page?
    >

    You may try to set a bookmard first and then used the code below to locate
    and paste what you want.
    e.g.
    Selection.GoTo What:=wdGoToBookmark, Name:="test" ' the test is a
    bookmark you have set before.
    Selection.Paste ' you may use paste or pastespecial method

    >3. How can the Word application suppress the prompt to "Save Changes" when
    >quitting the Excel application. I do not want the changes to be saved when
    >Excel quits.You can set this Saved Property of workbook to True if you

    want to close a modified workbook without either saving it or being
    prompted to save it.
    e.g.
    Sub test()
    Dim exapp As Excel.Application
    Set exapp = New Excel.Application
    exapp.Workbooks.Open "c:\book2.xls" 'you may need to establish a book2.xls
    exapp.Worksheets("Sheet1").ChartObjects(1).Chart.ChartArea.Copy
    Application.ActiveDocument.Content.PasteSpecial Link:=True,
    DataType:=wdPasteOLEObject
    exapp.ActiveWorkbook.Saved = True
    exapp.Quit
    Set exapp = Nothing
    End Sub


    Regards,
    Peter Huang
    Microsoft Online Partner Support
    Get Secure! www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.

    --------------------
    >From: "hmmm..." <>
    >Newsgroups:

    microsoft.public.word.oleinterop,microsoft.public.word.vba.general,microsoft
    .public.word.word97vba,microsoft.public.excel.charting,microsoft.public.exce
    l.misc,microsoft.public.excel.programming
    >References: <Q6O0b.1018$>

    <>
    <Uar2b.2643$>
    <>
    >Subject: Re: Word Document that shows Excel Chart
    >Lines: 66
    >X-Priority: 3
    >X-MSMail-Priority: Normal
    >X-Newsreader: Microsoft Outlook Express 5.50.4922.1500
    >X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4925.2800
    >Message-ID: <J%U2b.5211$>
    >Date: Wed, 27 Aug 2003 02:50:17 GMT
    >NNTP-Posting-Host: 209.179.141.125
    >X-Complaints-To:
    >X-Trace: newsread3.news.pas.earthlink.net 1061952617 209.179.141.125 (Tue,

    26 Aug 2003 19:50:17 PDT)
    >NNTP-Posting-Date: Tue, 26 Aug 2003 19:50:17 PDT
    >Organization: EarthLink Inc. -- http://www.EarthLink.net
    >Path:

    cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
    e.de!newsfeed.freenet.de!213.253.16.105.MISMATCH!mephistopheles.news.clara.n
    et!news.clara.net!colt.net!nycmny1-snf1.gtei.net!nycmny1-snh1.gtei.net!crtnt
    x1-snh1.gtei.net!news.gtei.net!newsfeed1.easynews.com!easynews.com!easynews!
    elnk-pas-nf1!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread3
    .news.pas.earthlink.net.POSTED!not-for-mail
    >Xref: cpmsftngxa06.phx.gbl microsoft.public.word.vba.general:41415

    microsoft.public.word.word97vba:68372 microsoft.public.excel.charting:33055
    microsoft.public.excel.misc:267741
    microsoft.public.excel.programming:410372
    microsoft.public.word.oleinterop:8621
    >X-Tomcat-NG: microsoft.public.excel.programming
    >
    >Hi,
    >
    >I followed your instructions and was able to open the Excel application

    from
    >the Word application (I got it to work with Microsoft Excel 9.0 Object
    >Library- Office 2000). I did this with a "test" Excel application that

    uses
    >workbook_open() to modify the chart when the Excel workbook is opened.
    >Everything works fine in my test example.
    >
    >When I changed the macro in the Word document to reference my "real" Excel
    >application, I got an error. The "real" Excel application has a 3rd party
    >add-in that has an interface to a DDE server (on request, the DDE server
    >returns data from an outside source). In workbook_open(), a request is made
    >to retrieve data from the DDE server. This call fails. So the Excel
    >application works fine stand-alone, but when it is opened from the Word
    >document, it doesn't understand the calls to the DDE server.
    >
    >1. What must I do to get the Excel application to understand the calls to
    >the DDE server when opened from the Word application?
    >
    >2. From the Word application, how do I position the Excel chart at a
    >certain place on a certain page?
    >
    >3. How can the Word application suppress the prompt to "Save Changes" when
    >quitting the Excel application. I do not want the changes to be saved when
    >Excel quits.
    >
    >Thanks!
    >
    >"Peter Huang [MSFT]" <> wrote in message
    >news:...
    >> Hi,
    >>
    >> It seems that you have not make reference to the Microsoft Excel Object
    >> Library. You may do that by following the steps below.
    >> 1. Open the word application and Press Alt +F11, this will open Visual
    >> Basic for Editor.
    >> 2. Select Tool/reference menu and check the Microsoft Excel 10.0 Object
    >> Library<because mine is office 2002, so the version is 10.0>
    >> 3. Copy and paste the code below to the Editor
    >> Sub test()
    >> Dim exapp As Excel.Application
    >> Set exapp = New Excel.Application
    >> exapp.Workbooks.Open "c:\book2.xls" 'you may need to establish a

    book2.xls
    >> first, which include a chart in sheet1
    >> exapp.Worksheets("Sheet1").ChartObjects(1).Chart.ChartArea.Copy
    >> Application.ActiveDocument.Content.PasteSpecial Link:=True,
    >> DataType:=wdPasteOLEObject
    >> exapp.quit
    >> set exapp = Nothing
    >> End Sub
    >> 4. Press F5 to run the macro.
    >>
    >> You may have a try and let me know if this does the job for you.
    >>
    >> I create the sample code in VB6 not in the VBA editor of word, I am sorry
    >> for confusion. You may refer to code above , when you run the macro above
    >> will insert an excel chart object as a OLE object into word.
    >>
    >> Regards,
    >> Peter Huang
    >> Microsoft Online Partner Support
    >> Get Secure! www.microsoft.com/security
    >> This posting is provided "as is" with no warranties and confers no

    rights.
    >> --------------------

    >
    >
    >
     
    Peter Huang [MSFT], Aug 27, 2003
    #4
  5. Peter Huang [MSFT]

    hmmm... Guest

    Hi,

    The error:

    Run-time error '1004'
    Tne macro 'xyzCreate' cannot be found.

    occurs when the following is executed in workbook_open() of the Excel
    workbook.

    Range("A1").Select
    ActiveCell.Formula = the_query_string
    Selection.Application.Run "xyzCreate"

    This works fine when the workbook is opened in Excel. When Word tries to
    open it from a macro, the error occurs. I almost seems like the Excel
    add-in or some library no longer exists or is invisible when the Excel app
    is started from a Word macro.

    Thanks.

    By the way, your suggestion for positioning the Excel chart within Word
    using a bookmark worked. Also, your suggestion for closing the Excel app
    from Word without prompting for "Save", by setting the Saved property to
    true also worked. Thanks.


    "Peter Huang [MSFT]" <> wrote in message
    news:...
    > Hi
    >
    > >1. What must I do to get the Excel application to understand the calls

    to
    > >the DDE server when opened from the Word application?

    >
    > To isolate the problem, I want to collect some information.
    > 1. What error message do you get in your "real" Excel application?
    > 2. You may try to set the exapp.visible to true to see if the problem
    > persists.
    > e.g.
    > Sub test()
    > Dim exapp As Excel.Application
    > Set exapp = New Excel.Application
    > Exapp.visible = true
    > exapp.Workbooks.Open "c:\book2.xls" 'you may need to establish a book2.xls
    > exapp.Worksheets("Sheet1").ChartObjects(1).Chart.ChartArea.Copy
    > Application.ActiveDocument.Content.PasteSpecial Link:=True,
    > DataType:=wdPasteOLEObject
    > exapp.ActiveWorkbook.Saved = True
    > exapp.Quit
    > Set exapp = Nothing
    > End Sub
    > 3. You may try to open the excel application and then open the workbook by
    > automation, and then call the macro that will retrieve data from DDE.
    > e.g. exapp.Run "a.xls!testmacro" ' the testmacro is one module macro in
    > the a.xls file.
    >
    >
     
    hmmm..., Aug 27, 2003
    #5
  6. Hi,

    Where was the Macro "xyzCreate" located in? I have made a test that
    automation a excel from work, I can not reproduce the problem you
    encounter. Here is my test code.
    [Word Macro]
    Sub test()
    Dim exapp As Excel.Application
    Set exapp = New Excel.Application
    exapp.Workbooks.Open "c:\book1.xls"
    exapp.Visible = True
    End Sub

    [Excel Macro,book1.xls]
    Sub testex()
    MsgBox "hello"
    End Sub

    Private Sub Workbook_Open()
    Range("a1").Select
    Selection.Application.Run "testex"
    End Sub

    You may have a try and let me the result.

    Also, when you excel application run, the addin or library needed to run
    your macro is loaded aumatically, i.e if you start up the excel
    application, the addin or library has been loaded?


    Regards,
    Peter Huang
    Microsoft Online Partner Support
    Get Secure! www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    --------------------
    >From: "hmmm..." <>
    >Newsgroups: microsoft.public.excel.programming
    >References: <Q6O0b.1018$>

    <>
    <Uar2b.2643$>
    <>
    <J%U2b.5211$>
    <>
    >Subject: Re: Word Document that shows Excel Chart
    >Lines: 60
    >X-Priority: 3
    >X-MSMail-Priority: Normal
    >X-Newsreader: Microsoft Outlook Express 5.50.4922.1500
    >X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4925.2800
    >Message-ID: <NM43b.6318$>
    >Date: Wed, 27 Aug 2003 16:13:33 GMT
    >NNTP-Posting-Host: 209.178.188.215
    >X-Complaints-To:
    >X-Trace: newsread4.news.pas.earthlink.net 1062000813 209.178.188.215 (Wed,

    27 Aug 2003 09:13:33 PDT)
    >NNTP-Posting-Date: Wed, 27 Aug 2003 09:13:33 PDT
    >Organization: EarthLink Inc. -- http://www.EarthLink.net
    >Path:

    cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
    e.de!newsfeed.freenet.de!newsfeed.news2me.com!elnk-nf2-pas!newsfeed.earthlin
    k.net!stamper.news.pas.earthlink.net!newsread4.news.pas.earthlink.net.POSTED
    !not-for-mail
    >Xref: cpmsftngxa06.phx.gbl microsoft.public.excel.programming:410564
    >X-Tomcat-NG: microsoft.public.excel.programming
    >
    >Hi,
    >
    >The error:
    >
    >Run-time error '1004'
    >Tne macro 'xyzCreate' cannot be found.
    >
    >occurs when the following is executed in workbook_open() of the Excel
    >workbook.
    >
    >Range("A1").Select
    >ActiveCell.Formula = the_query_string
    >Selection.Application.Run "xyzCreate"
    >
    >This works fine when the workbook is opened in Excel. When Word tries to
    >open it from a macro, the error occurs. I almost seems like the Excel
    >add-in or some library no longer exists or is invisible when the Excel app
    >is started from a Word macro.
    >
    >Thanks.
    >
    >By the way, your suggestion for positioning the Excel chart within Word
    >using a bookmark worked. Also, your suggestion for closing the Excel app
    >from Word without prompting for "Save", by setting the Saved property to
    >true also worked. Thanks.
    >
    >
    >"Peter Huang [MSFT]" <> wrote in message
    >news:...
    >> Hi
    >>
    >> >1. What must I do to get the Excel application to understand the calls

    >to
    >> >the DDE server when opened from the Word application?

    >>
    >> To isolate the problem, I want to collect some information.
    >> 1. What error message do you get in your "real" Excel application?
    >> 2. You may try to set the exapp.visible to true to see if the problem
    >> persists.
    >> e.g.
    >> Sub test()
    >> Dim exapp As Excel.Application
    >> Set exapp = New Excel.Application
    >> Exapp.visible = true
    >> exapp.Workbooks.Open "c:\book2.xls" 'you may need to establish a

    book2.xls
    >> exapp.Worksheets("Sheet1").ChartObjects(1).Chart.ChartArea.Copy
    >> Application.ActiveDocument.Content.PasteSpecial Link:=True,
    >> DataType:=wdPasteOLEObject
    >> exapp.ActiveWorkbook.Saved = True
    >> exapp.Quit
    >> Set exapp = Nothing
    >> End Sub
    >> 3. You may try to open the excel application and then open the workbook

    by
    >> automation, and then call the macro that will retrieve data from DDE.
    >> e.g. exapp.Run "a.xls!testmacro" ' the testmacro is one module macro

    in
    >> the a.xls file.
    >>
    >>

    >
    >
    >
     
    Peter Huang [MSFT], Aug 28, 2003
    #6
  7. Peter Huang [MSFT]

    hmmm... Guest

    Hi Peter,

    xyzCreate is part of xyz Addin. I finally got this to work!

    Here's what I had to do in my Word macro to get the add-in loaded in Excel:

    With exapp
    .Workbooks.Add
    .AddIns("xyz").Installed = False
    .AddIns.Add "c:\win32app\xyz\api\dde\xyz.xla", False
    .AddIns("xyz").Installed = True
    .Workbooks.Close
    End With

    After that, the Excel workbook started up everything perfectly, and my chart
    was updated. Then I copied the chart from Excel and pasted into Word.

    Thanks for all your advice!


    "Peter Huang [MSFT]" <> wrote in message
    news:...
    > Hi,
    >
    > Where was the Macro "xyzCreate" located in? I have made a test that
    > automation a excel from work, I can not reproduce the problem you
    > encounter. Here is my test code.
    > [Word Macro]
    > Sub test()
    > Dim exapp As Excel.Application
    > Set exapp = New Excel.Application
    > exapp.Workbooks.Open "c:\book1.xls"
    > exapp.Visible = True
    > End Sub
    >
    > [Excel Macro,book1.xls]
    > Sub testex()
    > MsgBox "hello"
    > End Sub
    >
    > Private Sub Workbook_Open()
    > Range("a1").Select
    > Selection.Application.Run "testex"
    > End Sub
    >
    > You may have a try and let me the result.
    >
    > Also, when you excel application run, the addin or library needed to run
    > your macro is loaded aumatically, i.e if you start up the excel
    > application, the addin or library has been loaded?
    >
    >
    > Regards,
    > Peter Huang
    > Microsoft Online Partner Support
    > Get Secure! www.microsoft.com/security
    > This posting is provided "as is" with no warranties and confers no rights.
    > --------------------
     
    hmmm..., Aug 29, 2003
    #7
  8. Hi,

    I am glad I can help you. :)

    Regards,
    Peter Huang
    Microsoft Online Partner Support
    Get Secure! www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    --------------------
    >From: "hmmm..." <>
    >Newsgroups:

    microsoft.public.word.oleinterop,microsoft.public.word.vba.general,microsoft
    .public.word.word97vba,microsoft.public.excel.charting,microsoft.public.exce
    l.misc,microsoft.public.excel.programming
    >References: <Q6O0b.1018$>

    <>
    <Uar2b.2643$>
    <>
    <J%U2b.5211$>
    <>
    <NM43b.6318$>
    <>
    >Subject: Re: Word Document that shows Excel Chart
    >Lines: 60
    >X-Priority: 3
    >X-MSMail-Priority: Normal
    >X-Newsreader: Microsoft Outlook Express 5.50.4922.1500
    >X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4925.2800
    >Message-ID: <EUv3b.8312$>
    >Date: Thu, 28 Aug 2003 23:05:08 GMT
    >NNTP-Posting-Host: 216.244.32.252
    >X-Complaints-To:
    >X-Trace: newsread3.news.pas.earthlink.net 1062111908 216.244.32.252 (Thu,

    28 Aug 2003 16:05:08 PDT)
    >NNTP-Posting-Date: Thu, 28 Aug 2003 16:05:08 PDT
    >Organization: EarthLink Inc. -- http://www.EarthLink.net
    >Path:

    cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
    e.de!newsfeed.icl.net!newsfeed.fjserv.net!colt.net!nycmny1-snf1.gtei.net!nyc
    mny1-snh1.gtei.net!crtntx1-snh1.gtei.net!news.gtei.net!newsfeed1.easynews.co
    m!easynews.com!easynews!elnk-pas-nf1!newsfeed.earthlink.net!stamper.news.pas
    .earthlink.net!newsread3.news.pas.earthlink.net.POSTED!not-for-mail
    >Xref: cpmsftngxa06.phx.gbl microsoft.public.word.vba.general:41495

    microsoft.public.word.word97vba:68376 microsoft.public.excel.charting:33099
    microsoft.public.excel.misc:268366
    microsoft.public.excel.programming:411064
    microsoft.public.word.oleinterop:8629
    >X-Tomcat-NG: microsoft.public.excel.programming
    >
    >Hi Peter,
    >
    >xyzCreate is part of xyz Addin. I finally got this to work!
    >
    >Here's what I had to do in my Word macro to get the add-in loaded in Excel:
    >
    > With exapp
    > .Workbooks.Add
    > .AddIns("xyz").Installed = False
    > .AddIns.Add "c:\win32app\xyz\api\dde\xyz.xla", False
    > .AddIns("xyz").Installed = True
    > .Workbooks.Close
    > End With
    >
    >After that, the Excel workbook started up everything perfectly, and my

    chart
    >was updated. Then I copied the chart from Excel and pasted into Word.
    >
    >Thanks for all your advice!
    >
    >
    >"Peter Huang [MSFT]" <> wrote in message
    >news:...
    >> Hi,
    >>
    >> Where was the Macro "xyzCreate" located in? I have made a test that
    >> automation a excel from work, I can not reproduce the problem you
    >> encounter. Here is my test code.
    >> [Word Macro]
    >> Sub test()
    >> Dim exapp As Excel.Application
    >> Set exapp = New Excel.Application
    >> exapp.Workbooks.Open "c:\book1.xls"
    >> exapp.Visible = True
    >> End Sub
    >>
    >> [Excel Macro,book1.xls]
    >> Sub testex()
    >> MsgBox "hello"
    >> End Sub
    >>
    >> Private Sub Workbook_Open()
    >> Range("a1").Select
    >> Selection.Application.Run "testex"
    >> End Sub
    >>
    >> You may have a try and let me the result.
    >>
    >> Also, when you excel application run, the addin or library needed to run
    >> your macro is loaded aumatically, i.e if you start up the excel
    >> application, the addin or library has been loaded?
    >>
    >>
    >> Regards,
    >> Peter Huang
    >> Microsoft Online Partner Support
    >> Get Secure! www.microsoft.com/security
    >> This posting is provided "as is" with no warranties and confers no

    rights.
    >> --------------------

    >
    >
    >
     
    Peter Huang [MSFT], Aug 29, 2003
    #8
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hmmm...

    Re: Word Document that shows Excel Chart

    hmmm..., Aug 23, 2003, in forum: Microsoft Excel Programming
    Replies:
    2
    Views:
    451
    hmmm...
    Aug 25, 2003
  2. Jani

    question about - excel macro copy chart to word document

    Jani, Jan 16, 2004, in forum: Microsoft Excel Programming
    Replies:
    2
    Views:
    855
    Jon Peltier
    Jan 16, 2004
  3. JtR

    Excel VBA - Easy way to paste chart to word document ?

    JtR, Jun 8, 2004, in forum: Microsoft Excel Programming
    Replies:
    6
    Views:
    2,785
  4. Replies:
    2
    Views:
    936
  5. Barb Reinhardt

    Extracting Excel.Chart title from Embedded Excel Chart in PowerPoi

    Barb Reinhardt, Jun 11, 2008, in forum: Microsoft Excel Programming
    Replies:
    1
    Views:
    276
    Barb Reinhardt
    Jun 11, 2008
Loading...

Share This Page