View Single Post
 
Old 09-07-2017, 09:07 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote