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
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