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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing .prn file with VBA! 2

Status
Not open for further replies.

MrProgrammer

Programmer
Feb 1, 2002
41
TR
You know when you print a document, there is an option like "print to file". With this option, you can print a document into a .prn file, copy it into a floppy disk and carry it into other computers. Then in that computer's command prompt, you give a command like below,
c:\COPY /B ABC.PRN LPT1
so you print that .prn file in that computer.
I want to know whether there is a way of doing this with VBA code. I mean is there a way to use command prompt with VBA. I tried to use Sendkeys method after running command.com with Shell function and sent commands character by character but it didn't work. I got \ characters every time. I tried to use FileCopy method of File object but I don't know How I can represent the printer (LPT port) as destionation. Can you help me please?
 
Sub print_prn()

file_name="ABC" ' or your name variable here...

open "c:\prn_batch.bat" for output as #1
print #1, "c:\COPY /B "+file_name+".PRN LPT1"
close

shell("c:\prn_batch.bat")


end sub
 
Thank you ETID,
It's really good idea. There is something else I wonder. After running .bat file with shell function, a command prompt windows is opened. I want this window closed after its job is fhinished. I thought writing an exit command into the .bat file but eventhough it is executed, the window stays opened.
On the other hand, there is another point I wonder. Is there a way of printing a .prn file by hand (I mean without using command prompt).
 
Create a .pif that calls your batch file,(you can set an option to close on exit) then run the ".pif" from your shell command.

the following is from the "windows" help...search on PIF
****************************

To create or change a program information file (PIF) in Windows 2000

Open My Computer.
Do one of the following:
If you want to create a PIF file for a program, locate the program and right-click it. Then click Properties and change the default settings to match the program requirements.
If you want to change the settings of an existing PIF file, locate the shortcut to the program file and right-click it. Click Properties and make the appropriate changes.
Notes

Creating a program information file (PIF) for an MS-DOS-based program creates a shortcut to the program executable. All the settings saved in the PIF file are contained in the shortcut.
Prior to creating or making changes to the PIF, please review the MS-DOS-based program documentation. Changing the PIF affects how the program interacts with Windows 2000 Professional. The program may only work correctly with specific default settings.
To specify whether an MS-DOS-based program starts in a full screen or in a window, change the Run properties on the Program (or Shortcut) tab.
To view MS-DOS-based program output on the screen faster, after clicking Properties in step 2, on the Screen tab, select Fast ROM emulation under Performance. Please review the documentation that came with your video card to ensure it supports Fast ROM emulation.
To increase the performance of the MS-DOS-based program, you can allocate more memory. To make this change, after clicking Properties in step 2, on the Memory tab, set Expanded (EMS) memory or Extended (XMS) memory to Auto, and no limit will be imposed. If you experience program errors, set the value in the Total window to 8192. For more information on memory options, see Related Topics.
The Properties dialog box has replaced the PIF Editor used in earlier versions of Windows.
Related Topics





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top