Open textfile delimited with VBA

  • Thread starter Thread starter =?iso-8859-1?Q?Henrik_Wikstr=F6m?=
  • Start date 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
 
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
 
Back
Top