Hello...I am trying to loop through a large folder with many Word templates...I need to extract the names of the boomarks, fields, and macros in these templates. I have the following steps done:
1) Function to recursively loop through the directories
2) A nested function to get the file attributes
I am not very good with writing to text files. What I want to do is simply take the data I am getting from the function and write to a text file. This is in a recursive loop, so the text file should keep writing lines until the directory is finished. I have attached the function where I get the file attributes: (again, this is nested in another recursive function)
[vb]
Public Function getAttributes(fn1 As String)
Dim s1, j, m As String
Dim r As Document
Dim obj As Object
Dim str As String
str = Right(fn1, 4)
On Error Resume Next
Application.ScreenUpdating = False
If ((str = ".dot"
Or str = ".doc"
Then
Documents.Open FileName:=fn1
With Documents(1)
For Each aBook In .Bookmarks
j = fn1 & " " & .Bookmarks(aBook).Name
Next aBook
For Each amacro In .VBProject.VBComponents
If ActiveDocument.VBProject.Protection = 0 Then
If amacro.Name <> "This Document" Then
m = fn1 & " " & amacro.Name
End If
End If
Next amacro
For Each aBar In .CommandBars
If aBar.BuiltIn = False Then
n = fn1 & " " & aBar.Name
End If
Next aBar
For Each aField In .Fields
s1 = fn1 & " " & .Fields(aField).Code
Next aField
End With
Documents(1).Close
End If
Application.ScreenUpdating = True
End Function
[/vb]
so basically, I want to write m, n, and s1 to a text file(the strings being populated in the for loops)..does anyone know how to do this? I really need some help here. Thanks
1) Function to recursively loop through the directories
2) A nested function to get the file attributes
I am not very good with writing to text files. What I want to do is simply take the data I am getting from the function and write to a text file. This is in a recursive loop, so the text file should keep writing lines until the directory is finished. I have attached the function where I get the file attributes: (again, this is nested in another recursive function)
[vb]
Public Function getAttributes(fn1 As String)
Dim s1, j, m As String
Dim r As Document
Dim obj As Object
Dim str As String
str = Right(fn1, 4)
On Error Resume Next
Application.ScreenUpdating = False
If ((str = ".dot"
Documents.Open FileName:=fn1
With Documents(1)
For Each aBook In .Bookmarks
j = fn1 & " " & .Bookmarks(aBook).Name
Next aBook
For Each amacro In .VBProject.VBComponents
If ActiveDocument.VBProject.Protection = 0 Then
If amacro.Name <> "This Document" Then
m = fn1 & " " & amacro.Name
End If
End If
Next amacro
For Each aBar In .CommandBars
If aBar.BuiltIn = False Then
n = fn1 & " " & aBar.Name
End If
Next aBar
For Each aField In .Fields
s1 = fn1 & " " & .Fields(aField).Code
Next aField
End With
Documents(1).Close
End If
Application.ScreenUpdating = True
End Function
[/vb]
so basically, I want to write m, n, and s1 to a text file(the strings being populated in the for loops)..does anyone know how to do this? I really need some help here. Thanks