Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 09-07-2017, 09:07 PM
gmayor's Avatar
gmayor gmayor is offline Having Issues Applying a Macro Across Multiple Files.  Changes Just Don't Seem To Save. Windows 10 Having Issues Applying a Macro Across Multiple Files.  Changes Just Don't Seem To Save. Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,142
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Having Issues Applying a Macro Across Multiple Files.  Changes Just Don't Seem To Save. Run a macro on multiple docx. files 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
Having Issues Applying a Macro Across Multiple Files.  Changes Just Don't Seem To Save. looking for macro for multiple files bolk Word 3 05-03-2011 05:46 AM
Having Issues Applying a Macro Across Multiple Files.  Changes Just Don't Seem To Save. macro to pull data from multiple files psrs0810 Excel 2 10-25-2010 01:49 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:14 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft