Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default pasting charts to new bookmarks in Word

Hello, I have charts in Excel that I'm pasting into a Word
template that has preexisting bookmarks.
The bookmarks are named for the section of the report they are in.

For example, in section E, they are name E1, E2, E3, etc.

Several charts exist for each bookmark; e.g., E1a, E1b, E1c.
These bookmarks do NOT exist in the template.

What I'm doing is locating bookmark E1, and then inserting a new
bookmark above it for each of the charts that are subject to the
bookmark. This is the code:


For Each s In xlbook.Application.Charts
s.Activate
'extract name of Word bookmark from chart name
strBkmk = Left(s.Name, Len(s.Name) - 3) 'this would
be the E1 or E2 etc
s.ChartArea.Copy

If .ActiveDocument.Bookmarks.Exists(strBkmk) Then
With .Selection
.Goto What:=wdGoToBookmark, Name:=strBkmk
'move up to the next paragraph mark, pre-set
in the template, and insert another
.MoveUp Unit:=wdLine, Count:=1
.TypeParagraph
.MoveUp Unit:=wdLine, Count:=1
End With
'insert a new bookmark for that parameter's
production category
.ActiveDocument.Bookmarks.Add s.Name 'this
would be E1a or E1b etc.
.Selection.Collapse (wdCollapseStart)
'paste chart at bookmark, special, to save space
.Selection.PasteAndFormat (wdChartPicture)
Else
MsgBox "Bookmark for " & strBkmk & " does not
exist." & vbCr _
& "Fatal error: exiting program."
.Visible = True
GoTo xl_quit
End If
Next s


That's the snippet. What's happening is, it works fine
sometimes, and then other times one of the newly-created
bookmarks (E2c, perhaps) will end up at the end of the section
rather than grouped with the other E2 bookmarks.

This is what I'll end up with:

Section E
E1a
E1b
E1c
E2a
E2b
E3a
E3b
E3c
E2c

This causes me to have to manually cut the pasted chart from its
wrong placement and insert it with the group to which it belongs.
What the ##$$%$%. There is no rhyme or reason as to why this
happens. I've stepped through the code and can never catch it
misbehaving in the act.

Does anyone have any insight on this aberrant behavior??

Thank you,
Kate
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default pasting charts to new bookmarks in Word

In some cases your MoveUp may be moving in front of the last pasted chart,
so the next chart is going in out of order. This manipulation of bookmarks
can cause issues. Instead of moving up one line, what about moving left one
character?

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"Kate" wrote in message
...
Hello, I have charts in Excel that I'm pasting into a Word template that
has preexisting bookmarks.
The bookmarks are named for the section of the report they are in.

For example, in section E, they are name E1, E2, E3, etc.

Several charts exist for each bookmark; e.g., E1a, E1b, E1c. These
bookmarks do NOT exist in the template.

What I'm doing is locating bookmark E1, and then inserting a new bookmark
above it for each of the charts that are subject to the bookmark. This is
the code:


For Each s In xlbook.Application.Charts
s.Activate
'extract name of Word bookmark from chart name
strBkmk = Left(s.Name, Len(s.Name) - 3) 'this would be the E1
or E2 etc
s.ChartArea.Copy

If .ActiveDocument.Bookmarks.Exists(strBkmk) Then
With .Selection
.Goto What:=wdGoToBookmark, Name:=strBkmk
'move up to the next paragraph mark, pre-set in the
template, and insert another
.MoveUp Unit:=wdLine, Count:=1
.TypeParagraph
.MoveUp Unit:=wdLine, Count:=1
End With
'insert a new bookmark for that parameter's production
category
.ActiveDocument.Bookmarks.Add s.Name 'this would be E1a or
E1b etc.
.Selection.Collapse (wdCollapseStart)
'paste chart at bookmark, special, to save space
.Selection.PasteAndFormat (wdChartPicture)
Else
MsgBox "Bookmark for " & strBkmk & " does not exist." &
vbCr _
& "Fatal error: exiting program."
.Visible = True
GoTo xl_quit
End If
Next s


That's the snippet. What's happening is, it works fine sometimes, and
then other times one of the newly-created bookmarks (E2c, perhaps) will
end up at the end of the section rather than grouped with the other E2
bookmarks.

This is what I'll end up with:

Section E
E1a
E1b
E1c
E2a
E2b
E3a
E3b
E3c
E2c

This causes me to have to manually cut the pasted chart from its wrong
placement and insert it with the group to which it belongs. What the
##$$%$%. There is no rhyme or reason as to why this happens. I've
stepped through the code and can never catch it misbehaving in the act.

Does anyone have any insight on this aberrant behavior??

Thank you,
Kate



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default pasting charts to new bookmarks in Word

Damn, you're good! Right before using moveleft, I collapsed the
selection to
the start, so that I wouldn't insert the new bookmark inside of
the old one.
I ran an entire report, and it seems to work!

I love you! -Kate

Jon Peltier wrote:
In some cases your MoveUp may be moving in front of the last pasted chart,
so the next chart is going in out of order. This manipulation of bookmarks
can cause issues. Instead of moving up one line, what about moving left one
character?

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"Kate" wrote in message
...
Hello, I have charts in Excel that I'm pasting into a Word template that
has preexisting bookmarks.
The bookmarks are named for the section of the report they are in.

For example, in section E, they are name E1, E2, E3, etc.

Several charts exist for each bookmark; e.g., E1a, E1b, E1c. These
bookmarks do NOT exist in the template.

What I'm doing is locating bookmark E1, and then inserting a new bookmark
above it for each of the charts that are subject to the bookmark. This is
the code:


For Each s In xlbook.Application.Charts
s.Activate
'extract name of Word bookmark from chart name
strBkmk = Left(s.Name, Len(s.Name) - 3) 'this would be the E1
or E2 etc
s.ChartArea.Copy

If .ActiveDocument.Bookmarks.Exists(strBkmk) Then
With .Selection
.Goto What:=wdGoToBookmark, Name:=strBkmk
'move up to the next paragraph mark, pre-set in the
template, and insert another
.MoveUp Unit:=wdLine, Count:=1
.TypeParagraph
.MoveUp Unit:=wdLine, Count:=1
End With
'insert a new bookmark for that parameter's production
category
.ActiveDocument.Bookmarks.Add s.Name 'this would be E1a or
E1b etc.
.Selection.Collapse (wdCollapseStart)
'paste chart at bookmark, special, to save space
.Selection.PasteAndFormat (wdChartPicture)
Else
MsgBox "Bookmark for " & strBkmk & " does not exist." &
vbCr _
& "Fatal error: exiting program."
.Visible = True
GoTo xl_quit
End If
Next s


That's the snippet. What's happening is, it works fine sometimes, and
then other times one of the newly-created bookmarks (E2c, perhaps) will
end up at the end of the section rather than grouped with the other E2
bookmarks.

This is what I'll end up with:

Section E
E1a
E1b
E1c
E2a
E2b
E3a
E3b
E3c
E2c

This causes me to have to manually cut the pasted chart from its wrong
placement and insert it with the group to which it belongs. What the
##$$%$%. There is no rhyme or reason as to why this happens. I've
stepped through the code and can never catch it misbehaving in the act.

Does anyone have any insight on this aberrant behavior??

Thank you,
Kate



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pasting charts to Word without Gridlines Brian Excel Worksheet Functions 5 August 10th 09 09:10 PM
Pasting excel charts into word as bitmaps RWright Excel Discussion (Misc queries) 2 February 4th 09 06:53 PM
Pasting Charts into Word then resizing them [email protected] Excel Discussion (Misc queries) 1 July 19th 07 09:35 PM
Pasting charts to Word from Excel as picture Hari Charts and Charting in Excel 5 July 5th 06 08:04 PM
Pasting Excel charts into Word Theresa Charts and Charting in Excel 4 January 27th 06 03:36 AM


All times are GMT +1. The time now is 01:42 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"