Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Here is my code, quick question about looping

Status
Not open for further replies.

ceyhorn

Programmer
Nov 20, 2003
93
US
I am trying to loop through a folder of word files to extract some data from them and then close it and move on. The problem is that it just keeps looping through the files over and over again. If I do not know how many files are in the folder how can I make it stop after going through the files once? Here is the code i have so far. Is there a way to create a log of the files it has opened and then check against that to see? Just a thought.

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True

Dim targetgroup As String
Dim appnum As String

ChDir "C:\Documents and Settings\ceyhorn\Desktop\VOCA\"
MyFile = Dir("*.doc", vbNormal)
Do While MyFile <> ""

Documents.Open FileName:="C:\Documents and Settings\ceyhorn\Desktop\VOCA\" & MyFile
TextBox1.Text = MyFile
targetgroup = ActiveDocument.FormFields("VAPNTx5").Result '_
TextBox2.Text = targetgroup
ActiveDocument.Close


Loop
wrdApp.Visible = False

Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

Thanks a ton,

chris
 
Add a line at the end of loop:

[tt] MyFile = Dir
Loop[/tt]

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top