Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-21-2019, 06:28 AM
chrscote chrscote is offline Want to remove first 2 blank pages Windows 7 64bit Want to remove first 2 blank pages Office 2010 64bit
Novice
Want to remove first 2 blank pages
 
Join Date: Aug 2016
Posts: 12
chrscote is on a distinguished road
Exclamation Want to remove first 2 blank pages

I have a script in DOORS that creates a document with a table. However, for some reason, it always adds 2 empty pages before the actual content. I have been trying to write a simple script that will delete these first 2 pages, but it's not working. Here's the code I'm using:


Code:
Sub removeExtraPages()
    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
End Sub

I found this code from this forum, but can't seem to figure out what is causing the problem. I'm hoping someone can help me out.


Chris
Reply With Quote
  #2  
Old 06-21-2019, 11:52 AM
kilroy kilroy is offline Want to remove first 2 blank pages Windows 10 Want to remove first 2 blank pages Office 2016
Competent Performer
 
Join Date: Sep 2016
Location: Southern Ontario
Posts: 118
kilroy is on a distinguished road
Default

Cannot put code tag for some reason.


try this:



Sub DeleteFirstTwoPages()
Dim oSec As section
Dim i As Integer
Application.ScreenUpdating = False
For Each oSec In ActiveDocument.Sections
For i = 1 To 2
oSec.Range.Select
Selection.Collapse
ActiveDocument.Bookmarks("\page").Range.Delete 'this deletes current page
Next i
Next oSec
Application.ScreenUpdating = False
End Sub

Last edited by kilroy; 06-21-2019 at 11:53 AM. Reason: more content
Reply With Quote
  #3  
Old 06-21-2019, 12:05 PM
gmaxey gmaxey is offline Want to remove first 2 blank pages Windows 10 Want to remove first 2 blank pages Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,484
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

If the first actual content is the table then:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Range
  Set oRng = ActiveDocument.Range
  oRng.End = ActiveDocument.Tables(1).Range.Start
  oRng.Delete
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #4  
Old 06-24-2019, 05:45 AM
chrscote chrscote is offline Want to remove first 2 blank pages Windows 7 64bit Want to remove first 2 blank pages Office 2010 64bit
Novice
Want to remove first 2 blank pages
 
Join Date: Aug 2016
Posts: 12
chrscote is on a distinguished road
Default

Thank you so much Kilroy. That script is exactly what I need for my application.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Want to remove first 2 blank pages Delete blank pages Dimsok Word VBA 18 11-14-2014 12:30 PM
Want to remove first 2 blank pages deleting blank pages thauser Word 3 05-27-2014 01:56 AM
Want to remove first 2 blank pages remove blank lines in between jolinchew Excel 4 08-01-2013 06:09 AM
Want to remove first 2 blank pages Deleting blank pages Microsoftenquirer1000 Word 14 08-27-2012 01:24 PM
hidden blank pages mljm Word 3 06-19-2009 03:18 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:03 PM.


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