Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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
 



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 03:56 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