Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-05-2017, 07:21 AM
ballpoint ballpoint is offline Loop Through all documents in a folder Windows 10 Loop Through all documents in a folder Office 2016
Advanced Beginner
Loop Through all documents in a folder
 
Join Date: Sep 2017
Posts: 40
ballpoint is on a distinguished road
Question Loop Through all documents in a folder

I am trying to run a similar macro to https://www.msofficeforums.com/word-...ocx-files.html (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:

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
    Call foot2inline
    .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
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop Through all documents in a folder How to open Documents folder directly from CTRL+O of Open folder on QAT scvjudy Word 2 08-11-2014 10:58 PM
Loop Through all documents in a folder Content of all documents in folder changes to match one of them jemmac2525 Word 2 11-11-2013 12:32 AM
Office 2010 Can't Open Or Save Documents in My Documents Folder trippb Office 1 07-12-2013 07:29 AM
Loop Through all documents in a folder Documents saved to wrong folder stevecarr Word 1 09-22-2011 05:32 AM
Loop through folder of workbooks and copy range to other workbook Snvlsfoal Excel Programming 3 07-29-2011 05:55 AM

Other Forums: Access Forums

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