p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Microsoft Office > Other Office > Word VBA
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Word VBA Discuss using VBA to program Word.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 30th, 2009, 06:19 PM
Authorized User
Points: 57, Level: 1
Points: 57, Level: 1 Points: 57, Level: 1 Points: 57, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Write Excel VBA Code to Target Bookmark in Word Doc

I have a word doc called myGraph.doc and a bookmark within the document entitled myMark. What I would like to do is have code within an Excel Doc place a graph at the designated bookmark ("myMark").

I have code written in Excel that opens the above Word document (myGraph.doc) and places a picture of the graph in it. The problem is that it places it in the Title area of the document and not at the designated bookmark.

When I attempt to add code to place the picture chart at the designated spot, I get an 4198 run time error - Application defined or object defined error. The following is the code producing the error:

Code:
Dim bMark As Bookmark
If Not IsNull(ActiveChart) Then 
Set bMark = WDApp.ActiveDocument.Bookmarks("myMark")
 
' Paste chart at cursor position
WDApp.Selection.PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, _
Placement:=bMark, DisplayAsIcon:=False
End If
I am pretty sure it bombs at the Placement:=bMark spot. Any ideas as to what I am doing wrong? I am a .Net developer and am pretty green when it comes to developing in VBA.

Thanks (in advance) for your help!
__________________
SLBIBS

Last edited by slbibs : July 31st, 2009 at 10:34 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old July 30th, 2009, 10:56 PM
Friend of Wrox
Points: 1,449, Level: 15
Points: 1,449, Level: 15 Points: 1,449, Level: 15 Points: 1,449, Level: 15
Activity: 17%
Activity: 17% Activity: 17% Activity: 17%
 
Join Date: Sep 2005
Location: , , .
Posts: 420
Thanks: 0
Thanked 14 Times in 14 Posts
Default

Can you try selecting the bookmark before pasting the chart. Something like

bMark.Select

Code:
Dim bMark As Bookmark
    If Not IsNull(ActiveChart) Then
         Set bMark = WDApp.ActiveDocument.Bookmarks("myMark")
        bMark.Select
' Paste chart at cursor position
         WDApp.Selection.PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, _
       Placement:=bMark, DisplayAsIcon:=False
    End If
Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old July 31st, 2009, 10:37 AM
Authorized User
Points: 57, Level: 1
Points: 57, Level: 1 Points: 57, Level: 1 Points: 57, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, thanks for your suggestion but I get the same error. I will keep hammering away at this. Any other suggestions are certainly welcome!
__________________
SLBIBS
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old July 31st, 2009, 10:47 AM
Authorized User
Points: 57, Level: 1
Points: 57, Level: 1 Points: 57, Level: 1 Points: 57, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK... I had this on another forum and got it resolved. This is what my code should have looked like:

Code:
Dim bMark As Bookmark
If Not IsNull(ActiveChart) Then
    'move the cursor to the correct location
    WDApp.Selection.GoTo What:=wdGoToBookmark, Name:="myMark"
    'Paste chart at cursor position
    WDApp.Selection.PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, Placement:=wdInLine, DisplayAsIcon:=False
End If
__________________
SLBIBS
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i get vb printer.print code for a word doc choudhry.usman Word VBA 1 March 6th, 2008 10:46 PM
Copy text from 1 doc to other doc thru vba in word itchock Word VBA 2 December 29th, 2006 02:47 AM
Copy contents of Word doc & Paste in Excel - How?? robear Javascript How-To 1 August 23rd, 2006 04:22 PM
How to Copy contents of Word doc & Paste in Excel robear Pro PHP 0 August 21st, 2006 01:25 PM
How to insert an equation in a Word doc. Thru VBA? PedroZorro VB How-To 1 May 31st, 2005 01:36 PM



All times are GMT -4. The time now is 11:27 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc