5

Why does my code below not work? It highlights the .OpenText part and states:

Expected function or variable

Dim Indata As Excel.Workbook

Set Indata = Workbooks.OpenText(Filename:="C:\Users\thePunter\Desktop\Count_Types_062016.txt", DataType:=xlDelimited, Tab:=True)

2 Answers 2

7

You're trying to set the workbook variable while using the OpenText method but OpenText doesn't return a workbook reference. Do this instead

Dim Indata As Excel.Workbook
 Workbooks.OpenText(Filename:="C:\Users\thePunter\Desktop\Count_Types_062016.txt", DataType:=xlDelimited, Tab:=True)
Set Indata = ActiveWorkBook
Sign up to request clarification or add additional context in comments.

1 Comment

I hate that this is the answer. It should just return a workbook.
0

This should fix it -odd enough though-

'...
Dim Indata As Excel.Workbook
Call Workbooks.OpenText(Filename:="C:\Users\thePunter\Desktop\Count_Types_062016.txt", DataType:=xlDelimited, Tab:=True)
Set Indata = ActiveWorkbook
Indata.Close False
'...

However, while working with csv and txt files, I find highly effective the EOF command.

2 Comments

Thank you, All. I will give them all a try.
Please, check the green mark once an answer has fulfilled your answer and most importantly, try them, most of the users here won't be able to help if you "suddenly" (a week, a month after) change your original requirements or ask for new ones.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.