View Single Post
Old 11-05-2017, 07:21 AM
ballpoint ballpoint is offline Windows 10 Office 2016
Advanced Beginner
Join Date: Sep 2017
Posts: 42
ballpoint is on a distinguished road
Question Loop Through all documents in a folder

I am trying to run a similar macro to (actually, a much simplified version of it), but to no avail.

My idea is to run a macro I have (foot2inline) on a number of files, but I am somehow failing at that.

I have done this:

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
    Call foot2inline
    .Close SaveChanges:=True
  End With
  strFile = Dir()
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
Word appears to start something, but then everything goes back to a blank sheet. Is there anything obvious I am missing? Thanks!
Reply With Quote