Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 12-04-2020, 02:45 PM
Blondyvl Blondyvl is offline Delete pages Windows 10 Delete pages Office 2010
Novice
Delete pages
 
Join Date: Oct 2020
Posts: 7
Blondyvl is on a distinguished road
Question 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  
Old 12-05-2020, 03:07 PM
macropod's Avatar
macropod macropod is offline Delete pages Windows 10 Delete pages Office 2010
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

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]
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete pages How can I delete pages with no highlighted text? harpsichord Word VBA 9 04-30-2019 03:38 AM
Delete pages 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 pages 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

Other Forums: Access Forums

All times are GMT -7. The time now is 11:52 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