vba code for opening a .prn file


Posted by Robert yerby on February 01, 2002 12:56 AM

Can anyone tell me what the code would be for opening a file the name of which would need to be input by a user using an input box?
Thanks
Robert



Posted by Ivan F Moala on February 01, 2002 2:58 AM

Hi Robert
rather then use an input box to get the name of
the file to open try using the Applications
getopenfile, infact you should always endeavour
to use excels built in functions rather then
recreating the wheel....also cuts down on
programing for user input errors.

try something like this (Always more ways to skin a cat )

Option Explicit

Sub GetOpenPrnFile()
Dim sPrnFName As String

'Change const as required
Const AllowMultiSelect As Boolean = False
Const Caption As String = "Open Prn Files Only"
Const sFfilters As String = "Prn Files (*.prn), *.prn"
Const sS As String = " "

sPrnFName = Application.GetOpenFilename(sFfilters, , Caption, AllowMultiSelect)
If sPrnFName = "False" Then End

On Error GoTo Errf
Workbooks.Open sPrnFName

Exit Sub
Errf:
MsgBox Err.Number & sS & Err.Description, _
vbMsgBoxHelpButton, _
"File Error - " & _
Caption, Err.HelpFile, Err.HelpContext
End Sub

HTH


Ivan