4

I'm writing a microsoft word macro and having difficulty with vb.net. Please help.

Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
Nam G VU
  • 33,193
  • 69
  • 233
  • 372

3 Answers3

4

Check out the answers here - VB6 is almost identical to VBA.

  • You will need to add a reference to the Microsoft Scripting Runtime if you want to use FileSystemObject
  • Or you can just drop in the CDirDrill class which means you won't need any external references.
Community
  • 1
  • 1
MarkJ
  • 30,070
  • 5
  • 68
  • 111
  • so what you're saying is this is that this question is a duplicate of others on this site, only the others have answers... – ashleedawg May 31 '19 at 07:42
  • No that's not what I'm saying. This question is about VBA. The answers to the other questions are for VB6 and cannot all be used directly in VBA. For instance *"You will need to add a reference to the Microsoft Scripting Runtime if you want to use `FileSystemObject`"* – MarkJ May 31 '19 at 11:08
2

A Word Macro is usually written in VBA rather than VB.Net, I'm assuming that you meant VBA?

Use the FileSystemObject to access the filesystem and then use recursion to "walk" down. Here's a sample:

http://www.java2s.com/Code/VBA-Excel-Access-Word/File-Path/RecursiveSearchusingtheFileSystemObjectModel.htm

If it's actually VB.Net you're using, the idea will be the same but use System.IO.Directory rather than the FileSystemObject.

Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
0

I personally like the FileSystemObject approach. i normally set up a recursive search function like the one found here and have never had any problems.

user2780436
  • 583
  • 5
  • 9