![]() |
|
|
Thread Tools | Display Modes |
#2
|
||||
|
||||
![]()
Your macro doesn't do what you indicate it is supposed to do. Try the following, which does.
Note that C:\Desktop is not the usual location for the Windows desktop That would be Environ("USERPROFILE") & "\Desktop\" Code:
Option Explicit Public Sub PageAdd() Dim myFile As String Dim PathToUse As String Dim myDoc As Document Dim rngStory As Word.Range PathToUse = InputBox("Enter path to the documents:", _ "PageAdd", _ "C:\Temp") If PathToUse = "" Then Exit Sub If Right(PathToUse, 1) <> "\" Then PathToUse = PathToUse & "\" 'On Error Resume Next myFile = Dir$(PathToUse & "*.doc*") While myFile <> "" 'Open document Set myDoc = Documents.Open(PathToUse & myFile) Set rngStory = myDoc.Range If myDoc.BuiltInDocumentProperties("number of pages") Mod 2 <> 0 Then With rngStory .Collapse wdCollapseEnd .InsertBreak wdSectionBreakNextPage .End = myDoc.Range.End .Collapse wdCollapseEnd .InsertFile FileName:="C:\Desktop\NOTUSED.DOCX", link:=True With .Sections(1).Headers(wdHeaderFooterPrimary) .LinkToPrevious = False .Range.Text = "" End With End With myDoc.Close SaveChanges:=wdSaveChanges Else myDoc.Close SaveChanges:=wdDoNotSaveChanges End If 'Next file in folder myFile = Dir$() Wend End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Peter Carter | Word VBA | 27 | 12-15-2022 04:10 PM |
Macro for multiple RTF files | papapaleo | Word VBA | 1 | 07-28-2017 04:56 AM |
Macro to Pull Data From Multiple Files | Jess709 | Excel Programming | 30 | 05-20-2015 05:26 PM |
![]() |
bolk | Word | 3 | 05-03-2011 05:46 AM |
![]() |
psrs0810 | Excel | 2 | 10-25-2010 01:49 PM |