i have a function that opens a file makes changes then saves it to another file

and after that another function that takes this newly created file as an input and parses it.

the problem is it takes time for first function to write out the file and by that time the second file raises an error that file doesnt exist...

so i put up a while loop like this
VB Code:
  1. Do While Not FileExists(App.Path & "\a22.htm")
  2.     DoEvents
  3.     Sleep (500)
  4. Loop
  5.  
  6. Public Function FileExists(Filename As String) As Boolean
  7. Set fso = New FileSystemObject
  8.  
  9. If fso.FileExists(Filename) Then
  10.     FileExists = True
  11. Else
  12.     FileExists = False
  13. End If
  14. End Function

but still the error repeats .how do i make the second function wait for the file to be created