How to wait for text file to open before proceeding?

VBA_Cancer

New Member
Joined
Nov 6, 2017
Messages
11
Code:
Sub something()
Dim FilePath As String
Dim strFilename As String
Dim strTextLine As String
Dim iFile As Integer: iFile = FreeFile


strFilename = "C:\desktop\file.txt"

Open strFilename For Input As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=iFile]#iFile[/URL]  'read each line in text individually

Application.Wait (Now + 0.0000058) 'wait for about half a second

Do Until EOF(1)

Line Input [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , strTextLine
    Code

Close iFile#

End Sub
This is what I have at the moment. I paused the application for about half a second. I was wondering if there's a way to make it so that it only pauses when the text file is fully open.

Thanks n advance
 

Some videos you may like

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

mole999

Moderator
Joined
Oct 23, 2004
Messages
10,339
Office Version
2019, 2016, 2013
Platform
Windows
maybe DoEvents just after the file open is issued
 

Watch MrExcel Video

Forum statistics

Threads
1,099,330
Messages
5,467,976
Members
406,561
Latest member
Grappledog

This Week's Hot Topics

Top