Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-30-2018, 02:20 AM
shu shu is offline open word documents in folder and subfolders Windows 10 open word documents in folder and subfolders Office 2016
Novice
open word documents in folder and subfolders
 
Join Date: Jun 2018
Posts: 6
shu is on a distinguished road
Default open word documents in folder and subfolders

I have a userform where i can choose the desired folder. Then i try with the following script to run through the folder and subfolders, open the word docs, perform the procedure and close them after. However, I always receive the message "Document may be damaged" and i don't know why. Can someone pls help me?

BR shu


Sub BrowseDocuments()



Dim fsob As Object
Dim Verz As Object
Dim Datei As Object
Dim Folder As Object
Dim Subfolder As Object
Dim File As Object
Dim Dateien As Object
Dim Worddatei As Word.Document

'desired Folder
Set fsob = CreateObject("scripting.filesystemobject")
Set Verz = fsob.GetFolder(Ort)
Set Dateien = Verz.Files

'open files in Folder
For Each Datei In Dateien
If InStr(1, Datei.Path, "doc") Then
Set Worddatei = Documents.Open(Datei.Path)
NameWorddatei = Worddatei.Name
Debug.Print NameWorddatei
Call Main
Worddatei.Close SaveChanges:=wdSaveChanges
End If
Next

'run through Subfolder
For Each Folder In Verz.Subfolders
Set Subfolder = fsob.GetFolder(Folder.Path)

'open files in Subfolder
For Each File In Subfolder.Files
If InStr(1, File.Path, "doc") Then
Set Worddatei = Documents.Open(File.Path)
NameWorddatei = Worddatei.Name
Debug.Print NameWorddatei
Call Main
Worddatei.Close SaveChanges:=wdSaveChanges
End If
Next File
Next Folder

UserForm1.dp_st.Value = "Procedure is completed - Press the close button"

End Sub
Reply With Quote
  #2  
Old 07-30-2018, 02:51 AM
macropod's Avatar
macropod macropod is offline open word documents in folder and subfolders Windows 7 64bit open word documents in folder and subfolders Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

See the basic code for processing a single folder, in: https://www.msofficeforums.com/word-...html#post45854
and the modifications needed to loop through sub-folders, in: https://www.msofficeforums.com/word-...html#post47785
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extend Unlink Macro to reach documents in subfolders Rsloo Word VBA 3 06-14-2017 08:15 PM
Macro to change/convert/delete txt files in folder+subfolders NoS Word VBA 4 03-03-2016 12:10 PM
open word documents in folder and subfolders How to open Documents folder directly from CTRL+O of Open folder on QAT scvjudy Word 2 08-11-2014 10:58 PM
Microsoft Word 2013 Documents open as full version documents on two computers sporadically Jaydenc-Fortress Word 2 08-07-2014 12:34 AM
Office 2010 Can't Open Or Save Documents in My Documents Folder trippb Office 1 07-12-2013 07:29 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:11 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft