|
|
 |
| 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.
|
 |

July 30th, 2009, 06:19 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

July 30th, 2009, 10:56 PM
|
|
Friend of Wrox
|
|
Join Date: Sep 2005
Location: , , .
Posts: 420
Thanks: 0
Thanked 14 Times in 14 Posts
|
|
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
|

July 31st, 2009, 10:37 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

July 31st, 2009, 10:47 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |