#1
|
|||
|
|||
Delete pages
Please would it be possible for you to help me I have blank pages from a mailmerge that I can not delete it’s a three page merge and I want to delete the last page (page4).
Sub DeleteLastPage() Dim lngCharacters As Long Dim r As Range With ActiveDocument lngCharacters = .GoTo(wdGoToPage, wdGoToLast).Start Set r = .Range(lngCharacters - 1, .Range.End) r.Delete End With End Sub This macro above works when I run it in an individual file, however I can’t get it to run on a folder of word files in a folder, when I ask it to run using the following. Sub UpdateDocuments() Application.ScreenUpdating = False Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document strDocNm = ActiveDocument.FullName: strFolder = GetFolder If strFolder = "" Then Exit Sub strFile = Dir(strFolder & "\*.docx", vbNormal) While strFile <> "" If strFolder & "" & strFile <> strDocNm Then Set wdDoc = Documents.Open(FileName:=strFolder & "" & strFile, AddToRecentFiles:=False, Visible:=False) With wdDoc 'Call your other macro or insert its code here .Close SaveChanges:=True End With End If strFile = Dir() Wend Set wdDoc = Nothing Application.ScreenUpdating = True End Sub Function GetFolder() As String Dim oFolder As Object GetFolder = "" Set oFolder = CreateObject("Shell.Application").BrowseForFolder( 0, "Choose a folder", 0) If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path Set oFolder = Nothing End Function Many thanks |
#2
|
||||
|
||||
Kindly stop hijacking other threads with questions for which you have already been given the answer: https://www.msofficeforums.com/mail-...ment-when.html
Thread closed.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How can I delete pages with no highlighted text? | harpsichord | Word VBA | 9 | 04-30-2019 03:38 AM |
Macro to delete pages in Word 2007 | staicumihai | Word VBA | 4 | 11-07-2018 01:14 AM |
Delete specific things on all pages | Raulillo13 | OneNote | 0 | 02-05-2018 03:39 PM |
Delete blank pages | Dimsok | Word VBA | 18 | 11-14-2014 12:30 PM |
delete blank pages from mail merge document | blusea | Word | 0 | 12-17-2010 06:10 PM |