MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Open a textfile in vba

Posted by orjan on November 05, 2001 5:20 AM

I'm trying to open a text file using a button and vba code. My guess is this:

Private Sub CommandButton1_Click()
Dim filnavn As String

filnavn = "m:\regnskap\skifteksport\" + c5 + "_" + c6 + ".txt"
Workbooks.Open (filnavn)

End Sub

But it won't work. I gett a 1004 'File not foud' error.
Cell c5 holds the value of 'e69' and c6=9 and I have a file called e69_9.txt that I'm trying to load.

Please, can someone help me?

Orjan B

Posted by Mark O'Brien on November 05, 2001 6:18 AM

You need to put in the complete reference for the cells. e.g.

The value Cell C5 on Sheet 1 would be referenced as:


To use this in your example, just replace "C5" and "C6" with this statement and put in whatever sheetname these cells are located on.