Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    May 2002
    Location
    Atlanta, Georgia, USA
    Posts
    122
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word 2007 throwing errors on pasting Word.Chart

    I inherited a macro that does the following:

    1. Gathers data from the user in a form and inserts that data into a doc
    2. Creates a Word Chart
    3. Sets values in the chart (line series, legends)
    4. Copies the chart to the Clipboard
    5. Deletes the chart
    6. Pastes the chart at a Bookmark.


    This works fine in Word 2010, but I'm getting various errors in 2007, which the client needs. Here's some pertinent code:

    Create the chart object:
    Set alignChart = ActiveDocument.Shapes.AddChart.Chart

    < Do a bunch of stuff to the chart>

    alignChart.Copy
    alignChart.Delete

    ActiveDocument.Bookmarks("graph").Select
    Selection.PasteSpecial Link:=False, DataType:=23, Placement:=wdInLine, DisplayAsIcon:=False

    I get Error 4198 "Command Failed." on the PasteSpecial command in Word 2007.
    I've tried putting in various other DataTypes (type 23 doesn't even seem to be a supported value, so I'm not sure why it works.)

    When I try those, I get Runtime 5342 "The specified data type is unavailable."

    I've tried moving alignChart.Delete below the paste, but that doesn't seem to help. When I break the macro and step through it, I can sometimes get it to work.

    What am I doing wrong?

    Thanks!
    Bob
    Writing Consultant / Word Template Designer
    Words Connect

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Willow Grove, Pennsylvania, USA
    Posts
    196
    Thanks
    4
    Thanked 46 Times in 38 Posts
    I was seeing the same error in Word 2007. In addition, I was getting an "object does not support this method" error on the alignChart.Delete statement. After consulting http://blogs.msdn.com/b/officedevdoc...-and-word.aspx, I got this to work reliably:

    Code:
    Sub x()
        Dim ILS As InlineShape
        Dim alignChart As Chart
        
        Set ILS = ActiveDocument.InlineShapes.AddChart
        Set alignChart = ILS.Chart
        
        alignChart.Copy
        ILS.Range.Delete
        
        ActiveDocument.Bookmarks("graph").Select
        Selection.PasteSpecial DataType:=wdPasteBitmap
    End Sub

  4. #3
    2 Star Lounger
    Join Date
    May 2002
    Location
    Atlanta, Georgia, USA
    Posts
    122
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, that got me going. Your code snippet worked intermittently, which was farther than I'd gotten before. I still got the 4198 error on pasting in some cases. It seemed that if I ran the macro and got the error, then ran it again, it would work. It would also work in debug mode sometimes.

    My ultimate solution was to trap the error and then run the alignchart.copy and paste commands in the error handler. That works every time. It's not elegant, but at this point I'm okay with functional.

    Thanks again!
    Bob
    Writing Consultant / Word Template Designer
    Words Connect

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •