Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-03-2018, 04:34 AM
KvT Zdam KvT Zdam is offline "Index" all the items and delete in one go Windows 10 "Index" all the items and delete in one go Office 2016
Novice
"Index" all the items and delete in one go
 
Join Date: Feb 2018
Posts: 2
KvT Zdam is on a distinguished road
Default "Index" all the items and delete in one go

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 View Post
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

Last edited by KvT Zdam; 02-03-2018 at 11:21 AM.
Reply With Quote
  #2  
Old 02-03-2018, 01:07 PM
macropod's Avatar
macropod macropod is offline "Index" all the items and delete in one go Windows 7 64bit "Index" all the items and delete in one go Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Unless your bookmarks are actual page #s, I'd be surprised if the modified code would work properly.

In any event, without actually seeing the problem document, it can be difficult for anyone to help you resolve the issue. Can you attach a document to a post with some representative data (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-04-2018, 01:18 PM
KvT Zdam KvT Zdam is offline "Index" all the items and delete in one go Windows 10 "Index" all the items and delete in one go Office 2016
Novice
"Index" all the items and delete in one go
 
Join Date: Feb 2018
Posts: 2
KvT Zdam is on a distinguished road
Default

I'll post miniature version of the Excel code and make Word template to give a better insight. I think I mixed-up the code. I tried it again and seems to do better .

Code:
Sub DelBm()

Dim StrBM As String
       StrBM = "J_03"
Dim Rng As Range
 
With ActiveDocument
    Set Rng = Selection.GoTo(What:=wdGoToBookmark, Name:=StrBM)
    Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page")
    Rng.Delete
End With
End Sub
I misinterpreted what the "\page" bookmark really dit. I thought it was limited to one page.
That does explain a few of the problems i had:

"Current page, including the break at the end of the page, if any. The current page contains the insertion point. If the current selection contains more than one page, the "\Page" bookmark is the first page of the selection. Note that if the insertion point or selection is in the last page of the document, the "\Page" bookmark does not include the final paragraph mark"

I can't test the full document jet, but whit the older versions of the excel/word I have now this code left behind ==========section-end(continuous)========= and the chapters lose the sequential numbering:

4. Interne 8
5.1 Overzicht 9
5.2 Dagelijks 10
5.5 Halfjaar 27
5.6

This is after updating the full table of contents. But if I re-assign a view chapter headings it updates the rest as wel.
Reply With Quote
  #4  
Old 02-04-2018, 01:23 PM
macropod's Avatar
macropod macropod is offline "Index" all the items and delete in one go Windows 7 64bit "Index" all the items and delete in one go Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

As I said, I'd need to see the content as it appears in an actual document...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
delete a page, index



Similar Threads
Thread Thread Starter Forum Replies Last Post
"Index" all the items and delete in one go Deleting Undeletable text boxes pasted in from web pages TAfromKC Word 4 05-08-2017 04:53 PM
Can we define macros in a way to not misworking after deleting, renaming or moving the source file? tesoke Excel Programming 10 11-13-2015 09:30 AM
"Index" all the items and delete in one go deleting blank pages thauser Word 3 05-27-2014 01:56 AM
"Index" all the items and delete in one go deleting pages paul_pearson Word 4 03-22-2013 12:18 AM
"Index" all the items and delete in one go Deleting blank pages Microsoftenquirer1000 Word 14 08-27-2012 01:24 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:47 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft