Loop File Names


L

lq495

I need to be able to loop through and capture the file name of all .vsd files
in the current directory. This code gets the file name but doesn't loop
correctly.

Sub FileNameTOC()

Dim CurFileName As String
Dim currentDoc As String
Dim PathFileName As String
Dim PathName As String

currentDoc = ActiveDocument.Name

' Set the default pathname
PathName = CurDir & "\"
PathFileName = PathName & "*.vsd"


' This variable holds the file name
'CurFileName = Dir(PathFileName)

'Loop through each file name
'or Do while CurFileName <>""
While CurFileName <> ""
Debug.Print CurFileName
CurFileName = Dir(PathFileName)
Wend

How can i get the loop to work correctly?
 
Ad

Advertisements

Ad

Advertisements

J

John... Visio MVP

When you use the DIR command, you use the PathFileName parameter only to get
the first file name. When you want subsequent file names you omit it and
just use DIR():

CurFileName = Dir(PathFileName)
While CurFileName <> ""
CurFileName = Dir()
Wend

John... Visio MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top