P
Paul Schrum
MS Word 2007
I have limited experience programming Office applications. This is my
first effort with Word.
I have a recurrsive function which looks good on paper, but when I try
to run the macro I get
Compile error:
Type mismatch
The compiler highlites the first occurence of
recurseWriteFolderName (aFolder)
As you can see in the code below my sig, I have dim'd everything as
Folder.
Note, I have activated the reference to the Microsoft Runtime
Scripting library.
- Paul Schrum
===========
Dim count As Integer
Sub DirStructure()
count = 1
ThisDocument.Sections(1).Range.InsertAfter "test string"
Dim topLevelFolder As String
Dim fso As New FileSystemObject
Dim theFolders As Folders
Dim aFolder As Folder
topLevelFolder = "Q:\60146825\"
Set theFolders = fso.GetFolder(topLevelFolder).SubFolders
For Each aFolder In theFolders
recurseWriteFolderName (aFolder)
Next
End Sub
Sub recurseWriteFolderName(aFolder_ As Folder)
writeLine aFolder_.Name
Dim subFolder As Folder
For Each subFolder In aFolder_.SubFolders
count = count + 1
If count > 1026 Then
Return
End If
recurseWriteFolderName (subFolder)
Next
End Sub
Sub writeLine(textToWrite As String)
ThisDocument.Sections(1).Range.InsertAfter textToWrite
End Sub
I have limited experience programming Office applications. This is my
first effort with Word.
I have a recurrsive function which looks good on paper, but when I try
to run the macro I get
Compile error:
Type mismatch
The compiler highlites the first occurence of
recurseWriteFolderName (aFolder)
As you can see in the code below my sig, I have dim'd everything as
Folder.
Note, I have activated the reference to the Microsoft Runtime
Scripting library.
- Paul Schrum
===========
Dim count As Integer
Sub DirStructure()
count = 1
ThisDocument.Sections(1).Range.InsertAfter "test string"
Dim topLevelFolder As String
Dim fso As New FileSystemObject
Dim theFolders As Folders
Dim aFolder As Folder
topLevelFolder = "Q:\60146825\"
Set theFolders = fso.GetFolder(topLevelFolder).SubFolders
For Each aFolder In theFolders
recurseWriteFolderName (aFolder)
Next
End Sub
Sub recurseWriteFolderName(aFolder_ As Folder)
writeLine aFolder_.Name
Dim subFolder As Folder
For Each subFolder In aFolder_.SubFolders
count = count + 1
If count > 1026 Then
Return
End If
recurseWriteFolderName (subFolder)
Next
End Sub
Sub writeLine(textToWrite As String)
ThisDocument.Sections(1).Range.InsertAfter textToWrite
End Sub