Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-07-2017, 02:07 PM
Kajex Kajex is offline Having Issues Applying a Macro Across Multiple Files.  Changes Just Don't Seem To Save. Windows 8 Having Issues Applying a Macro Across Multiple Files.  Changes Just Don't Seem To Save. Office 2016
Novice
Having Issues Applying a Macro Across Multiple Files.  Changes Just Don't Seem To Save.
 
Join Date: Sep 2017
Posts: 2
Kajex is on a distinguished road
Default Having Issues Applying a Macro Across Multiple Files. Changes Just Don't Seem To Save.

As the title states, I'm attempting a (fairly difficult to me) macro that reads goes through a folder of Word files, determines if each file ends on an odd page. If that is the case, it adds a document from a location on my desktop. (This portion works on an individual document, when the code is run on its own). The macro then should save over the original file, and move onto the next. My issue lies in that once the command has finished, including updated save timestamps on my files, no change seems to have taken place. Without a distinct error flag being thrown, I'm pretty much at the end of my wits. Thanks in advance for any insight.

Current code is as follows:
Code:
Public Sub PageAdd()

Dim FirstLoop As Boolean
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim Response As Long
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

'Close all open documents before beginning

Documents.Close SaveChanges:=wdPromptToSaveChanges

'Boolean expression to test whether first loop
'This is used so that the FindReplace dialog will
'only be displayed for the first document

FirstLoop = True

'Set the directory and type of file to batch process

myFile = Dir$(PathToUse & "*.doc")

While myFile <> ""

    'Open document
    Set myDoc = Documents.Open(PathToUse & myFile)


        For Each rngStory In ActiveDocument.StoryRanges
            Do
                rngStory.Select
                
              If ActiveDocument.BuiltInDocumentProperties("number of pages") Mod 2 <> 0 Then
    Selection.EndKey Unit:=wdStory
    Selection.InsertBreak Type:=wdSectionBreakNextPage
    Selection.Collapse Direction:=wdCollapseEnd
    Selection.InsertFile FileName:="C:\desktop\NOTUSED.DOCX", Link:=True
    Selection.Sections(1).Headers(wdHeaderFooterPrimary).LinkToPrevious = False
    Selection.Sections(1).Headers(wdHeaderFooterPrimary).Range.Delete
    Selection.Sections(1).Footers(wdHeaderFooterPrimary).LinkToPrevious = False
    Selection.Sections(1).Footers(wdHeaderFooterPrimary).Range.Delete
    If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
        ActiveWindow.Panes(2).Close
    End If
    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
        ActivePane.View.Type = wdOutlineView Then
        ActiveWindow.ActivePane.View.Type = wdPrintView
    End If
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End If
    ActiveDocument.Save
                        
                Set rngStory = rngStory.NextStoryRange
            Loop Until rngStory Is Nothing
        Next

    'Close the modified document after saving changes

    myDoc.Close SaveChanges:=wdSaveChanges

    'Next file in folder

    myFile = Dir$()

Wend

End Sub


Last edited by macropod; 09-07-2017 at 02:52 PM. Reason: Added code tags
Reply With Quote
 

Thread Tools
Display Modes


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 09:20 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