Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get existing filename and print to file?

Status
Not open for further replies.

cheriberi

Technical User
May 27, 2003
60
US
Can anyone tell me how to use VBA in Word to:

1) Get the filename of the open Word document (without also pulling the file extension)

2) Then print to file using same filename plus file extension of .prn?

Thanks!
 
Don't know if this is exactly what you want. This form of .prn is a printer file. There is another type which is a space delimited text file which would require SaveAs instead but this option is not available to me in my current word 97 setup.

'--------------------------------------------------------
Sub test()
myname = ActiveDocument.Name
fname = Left(myname, Len(myname) - 4) & ".prn"
MsgBox (fname)
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, _
PrintToFile:=True, OutputFileName:=fname, Append:=False
End Sub
'---------------------------------------------------------


Regards
BrianB
** Let us know if you get something that works !
================================
 
Hi Tony,

I get an error at the "Left" command in the following line:

Code:
fname = Left(myname, Len(myname) - 4) & ".prn"

Any suggestions?
 
Sorry Brian! I called you Tony (who answered one of my other questions). I apologize!

[hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top