Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 02-24-2020, 12:19 AM
sakhtar6 sakhtar6 is offline Batch Editing Word documents Mac OS X Batch Editing Word documents Office 2011 for Mac
Novice
Batch Editing Word documents
 
Join Date: Feb 2020
Posts: 4
sakhtar6 is on a distinguished road
Default Error amde and corrected but still not working

I have modifies the code but it still freezes after the do you wish to process other files dialog box!

Code I am using is:

Code:
Public Sub BatchReplaceAllTrial()

Dim FirstLoop As Boolean
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim Response As Long

PathToUse = "Macintosh HD:Trial:"

        'Error handler to handle error generated whenever
        'the FindReplace dialog is closed

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 & "*.docx")

While myFile <> " "

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

    If FirstLoop Then

        'Display dialog on first loop only

        Dialogs(wdDialogEditReplace).Show

        FirstLoop = False

        Response = MsgBox("Do you want to process " & _
        "the rest of the files in this folder", vbYesNo)
        If Response = vbNo Then Exit Sub

    Else

        'On subsequent loops (files), a ReplaceAll is
        'executed with the original settings and without
        'displaying the dialog box again

        With Dialogs(wdDialogEditReplace)
            .ReplaceAll = 1
            .Execute
        End With

    End If
    
    
        'Close the modified document after saving changes

    myDoc.Close SaveChanges:=wdSaveChanges

        'Next file in folder

    myFile = Dir$()

Wend

End Sub
I have looked at multiple peoples posts and this seems to work for them and I cannot seem to get it to do so for me!

Last edited by macropod; 02-24-2020 at 03:47 AM. Reason: Added code tags (again)...
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch Editing Word documents Batch applying a macro to remove Header and Footer using Batch Auto Addin Edszx Word VBA 2 05-27-2019 11:16 PM
Editing Word documents through VBA in SharePoint algecan Word VBA 0 09-26-2018 05:23 AM
batch extract all tables in multiple word documents ZaidaBa Word Tables 3 05-08-2017 10:22 PM
Emailed documents locked for editing by someone else jibbs Office 1 09-30-2015 05:12 AM
Batch Editing Word documents Batch create Word documents cdfj Word VBA 6 11-07-2012 01:03 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:52 PM.


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