Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-27-2014, 05:35 AM
prakhil prakhil is offline Run a macro on multiple documents Windows 8 Run a macro on multiple documents Office 2013
Novice
Run a macro on multiple documents
 
Join Date: Jun 2014
Posts: 1
prakhil is on a distinguished road
Question Run a macro on multiple documents

Hi All,
Thanks for the superb code in https://www.msofficeforums.com/word-...ocx-files.html, though i am having some problem in running the same. There aren't any errors but there is something i am missing and not aware of.



i need you help to run this macro on 500 .docx files kept in a folder, below is the code:

Code:
Sub UpdateDocuments() 
    Application.ScreenUpdating = False 
    Dim strFolder As String, strFile As String, wdDoc As Document 
    Dim rng As Range 
    Dim docSourse 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 
             'Call your other macro or insert its code here
             'Highlight all misspelled words.
             'Copy all misspelled words to new document.
            Set docSource = ActiveDocument 
            For Each rng In docSource.SpellingErrors 
                rng.Font.Color = wdColorRed 
                rng.Font.Bold = True 
            Next 
            .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, "Choose a folder", 0) 
    If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.path 
    Set oFolder = Nothing 
End Function
-----------------------------

on running this macro, i am getting an option to select the folder, i select the folder as well but the macro is running on just one file and not on all of the files. Please can you help me with this ?

Last edited by macropod; 06-27-2014 at 06:15 AM. Reason: Added code tags & formatting
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge multiple word documents [Macro] Arran [BMI] Word 2 06-18-2018 08:21 PM
Macro to copy cell info to multiple documents Patrick Innes Word VBA 2 02-18-2015 08:38 PM
Run a macro on multiple documents Updating multiple documents at once 1zillion Word 1 08-28-2014 12:18 AM
Multiple page document to individual multiple page documents Legger Mail Merge 3 06-15-2014 06:36 AM
Macro for find/replace (including headers and footers) for multiple documents jpb103 Word VBA 2 05-16-2014 04:59 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:38 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