Advertisement
kelvinella

Untitled

Jun 1st, 2023
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. Sub RunMacroOnAllFilesInFolder()
  2. Dim flpath As String, fl As String
  3. flpath = InputBox("Please enter the path to the folder you want to run the macro on.")
  4. If flpath = "" Then Exit Sub
  5.  
  6. If Right(flpath, 1) <> Application.PathSeparator Then flpath = flpath & Application.PathSeparator
  7. fl = Dir(flpath & "*.docx")
  8. Application.ScreenUpdating = False
  9. Do Until fl = ""
  10. MyMacro flpath, fl
  11. fl = Dir
  12. Loop
  13. End Sub
  14.  
  15. Sub MyMacro(flpath As String, fl As String)
  16. Dim doc As Document
  17. Set doc = Documents.Open(flpath & fl)
  18. 'Do stuff
  19. doc.Save
  20. doc.Close SaveChanges:=False
  21. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement