I show you a way to do it:
Sub Extract_and_Save_as_PRN()
Dim mPath, wb As Workbook
mPath = "Select a file type *.xl*"
If MsgBox(mPath, vbOKCancel) = vbCancel Then Exit Sub
mPath = Application.GetOpenFilename("Excel Files (*.xl*), *.xl*", Title:=mPath)
If mPath = False Then Exit Sub
Set wb = Workbooks.Open(mPath, ReadOnly:=True)
Set mPath = Nothing: On Error Resume Next
Set mPath = Application.InputBox("Select any cell in the sheet to extract", Type:=8)
If mPath Is Nothing Then
wb.Close False
End
End If
On Error GoTo 0
Application.ScreenUpdating = False: DoEvents
mPath.Parent.Copy
mPath = ThisWorkbook.Path & "\" & ActiveSheet.Name & ".prn"
If Dir(mPath) <> "" Then
Kill mPath
Application.Wait DateAdd("s", 1, Now)
End If
ActiveWorkbook.SaveAs mPath, FileFormat:=xlTextPrinter
ActiveWorkbook.Close False
wb.Close False
MsgBox "Saved file '" & mPath & "'"
End
End Sub
Bookmarks