Open textfile delimited with VBA

  • Thread starter =?iso-8859-1?Q?Henrik_Wikstr=F6m?=
  • Start date
?

=?iso-8859-1?Q?Henrik_Wikstr=F6m?=

I want to use (something like) below VBA code to open an
unspecified file with specified delimited characters. I.e.
how to make the file path "C:\PLC511A3_DB105.prn" dynamic?
Is there a command that only returns the file path?
Regards,
Henrik

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 2003-07-31 by Henrik Wikström
'

'
Workbooks.OpenText Filename:= _
"C:\PLC511A3_DB105.prn", Origin:= _
xlWindows, StartRow:=1, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, _
1), Array(6, 1), Array(13, 1), Array(47, 1), Array
(52, 1), Array(66, 1), Array(79, 1))

........ e.t.c.

End Sub
 
J

Jim Rech

One way to get a filename from the user and open the file is like this:

Sub OpenDemo()
Dim FName As Variant
FName = Application.GetOpenFilename("Prn files (*.prn),*.prn")
If FName <> False Then
Workbooks.OpenText Filename:=FName, _
DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, _
1), Array(6, 1), Array(13, 1), Array(47, 1), _
Array(52, 1), Array(66, 1), Array(79, 1))
Else
MsgBox "cancelled"
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Open File 2
Cannot open text workbook 1
Can you help me solve! 1
macro interruption: help!!! 4
Modify Macro Code Depending on Excel Version 11
Macro Error 6
Text Import Wizard 1
Open delimited file 3

Top