Hi,
(I changed the topic title to better subscribe the post)
A while back you guys helped me design a nice script to write Excel tables to Word

. We're now making 200 page rapports in seconds!!! It works by looking for word Bookmarks and then looking for corresponding named ranges.
A few tables don't get exported if the're not filled or when they're not selected. In sort:
Code:
If .Bookmarks.Exists(strBkMk) Then
Set wdRng = .Bookmarks(strBkMk).Range
wdRng.Paste
With Macropod's code i managed to delete the page if no table was exported.
Quote:
Originally Posted by macropod
That's about it, though you don't need to use Selection:
Code:
Dim Rng As Range, iPage As Long
iPage = 2
With ActiveDocument
Set Rng = .GoTo(What:=wdGoToPage, Name:=iPage)
Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page")
Rng.Delete
End With
A few modifications;
Code:
sub DelBm(strBkMn)
Dim Rng As Range
Set Rng = .GoTo(What:=wdGoToPage, Name:=strBkMn)
Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page")
Rng.Delete
|
A lot of times it completely mashes up the format and layout because there is stuff left behind when a page is deleted. Selection End doubles and a page turn 90 degrees. Bank pages are left behind and so on. Chapter number get left out or become 1.1.3 instead if 1.2.
I was thinking about making a script to identify everything on the page. Storing in a variant or array and then setting the range to everything. I think the Rng.Delete should work then. But I'm wondering if there is a better approach.
Thanks for a the great insights so far!
Koen