Jump to content

Please read the Forum Rules before posting.

Photo

Running a macro on all files in a folder


  • Please log in to reply
2 replies to this topic

#1 Josh Bond

Josh Bond

    Administrator

  • Administrators
  • PipPipPipPipPip
  • 2,891 posts
  • LocationGallatin, TN
Offline

Posted 07 January 2012 - 11:44 PM

This is for "advanced" module creators--folks who know what a macro is, how to use it, how to install it, etc. This is not that hard but if your not familiar with Macros, it will be.

This macro opens each file in your folder. While the file is open, this macro calls another macro that contains the edits you want made. Let's say you want to search/replace text, or change fonts, or change 25 formatting issues. And you don't want to open 300 files to run the macro on each file. Mickeysoft Word let's ya do this. As usual, lines with ' are explanatory comments.

'You can name this whatever you want. DoLangesNow happens to be the name of this macro.
'You will run this macro name...

Sub DoLangesNow()
Dim file
Dim path As String

' Path to your folder. MY folder is listed below. I bet yours is different.
' make SURE you include the terminating "\"
'YOU MUST EDIT THIS.
path = "F:\lange\OT\gen\footnote\"

'Change this file extension to the file you are opening. .htm is listed below. You may have rtf or docx.
'YOU MUST EDIT THIS.
file = Dir(path & "*.htm")
Do While file <> ""
Documents.Open FileName:=path & file

' This is the call to the macro you want to run on each file the folder
'YOU MUST EDIT THIS. lange01 is my macro name. You put yours here.
Call lange01

' Saves the file
ActiveDocument.Save
ActiveDocument.Close
' set file to next in Dir
file = Dir()
Loop
End Sub



#2 BaptizedBeliever

BaptizedBeliever

    Christian

  • Members (T)
  • PipPipPipPipPip
  • 924 posts
Offline

Posted 08 January 2012 - 06:28 PM

That's cool. I don't know that I'd use it now that you've gave the combining macro. But thanks for posting it.

Brad

#3 asmae

asmae

    New to Bible Support

  • Members
  • Pip
  • 1 posts
Offline

Posted 01 March 2017 - 08:50 AM

I know this is an old post but thank you very much for this well explained macro. You're a life saver.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users




Similar Topics



Latest Blogs