PDA

View Full Version : For Input as #1 Question



vzachin
04-21-2009, 04:50 AM
hi,

how can i modify the following code so that it will run on a .txt file that is already opened.i will only have one .txt file opened and the name of the file will not always be the same.


Sub GetTextTest1()
Dim InputData, sTxt, i As Long
Open "C:\file2.txt" For Input As #1
Do While Not EOF(1)
i = i + 1
Line Input #1, InputData
Cells(i, 1) = InputData
Loop
Close #1
End Sub


thanks
zach

mdmackillop
04-21-2009, 06:05 AM
I'm sure there is a better way, but this uses Word Tasks to return running tasks. You can parse the File name from t, which just leaves the path to find.


Option Explicit
Sub Tasks()
Dim wdApp As Object
Dim i As Long
Dim t As String
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0

For i = 1 To wdApp.Tasks.Count
t = wdApp.Tasks(i)
If InStr(1, t, "txt") > 0 Then MsgBox t
Next
wdApp.Quit
Set wdApp = Nothing
End Sub

vzachin
04-21-2009, 06:17 AM
hi malcolm,

thanks for the input. i'll try to figure out how this works
zach