View Single Post
 
Old 03-23-2017, 12:17 AM
Yisrael Yisrael is offline Windows 10 Office 2016
Novice
 
Join Date: Mar 2017
Posts: 9
Yisrael is on a distinguished road
Default Failed to apply macro to files in folder

Hey,

First of all I want to mention my bad English, I hope you can understand me anyway.

Well, I try to run macro on multiple files in a folder, on a particular computer it works well, but on another computer the macro only runs on one file in a folder.
I have debugged using F8 and I see that the macro identifies the files, that is, it enters the loop 3 times as many files in the folder.

I have run the search command on each file from the files in its own right and it works well - which tells me that the search code is correct.

Where can this be the problem ?!

Thank you!

It is worth noting that I took this code from here

Code:
Sub UpdateDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, wdDoc As Document
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.docx", vbNormal)
While strFile <> ""
  Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
  With wdDoc

     With Selection.Find
        .ClearFormatting
        .Format = True
        .text = ""
        .Font.NameBi = "Arial"
        .Font.SizeBi = 11
        .Replacement.text = ""
        .Replacement.Font.NameBi = "david"
        .Replacement.Font.SizeBi = 20
        .Wrap = wdFindContinue
        .Execute Replace:=wdReplaceAll
    End With
    
    .Close SaveChanges:=True
  End With
  strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
 
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Select a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
Reply With Quote