Solved

Printing .PRN files through VBA

Posted on 2006-11-20
12
2,456 Views
Last Modified: 2013-12-02
Is there anyway of printing .PRN files without having to invoke dos or notepad...

I am wanting something like filecopy but I cant get anything to work. Our printers are stored on a network on an IP port.

Also, what is the application that allows you to view PRN files, Ive seen it in windows before but can't seem to find it anywhere, I assumed it is pre-loaded with MS word?

Thanks,

Matt
0
Comment
Question by:generali
  • 7
  • 4
12 Comments
 
LVL 58

Expert Comment

by:harfang
ID: 17978570
Hello generali,

Normally, you should be able to copy a file to the printer with the VB FileCopy command. As destiation, use "LPT1", either as "device" ("LPT1:") or as filename ("lpt1.ext"). This implies that you have created a "DOS" device for the printer, naturally. For example:

    FileCopy "C:\temp\output.prn", "lpt1"

I don't know of an application that can view just any PRN files, although I remember one for HP printers from many years back, and there are several for postscript files, such as ghostview. I would think this is highly printer specific.

Cheers!
(°v°)
0
 
LVL 2

Author Comment

by:generali
ID: 17978665
Hi,

My DOS has been disabled by IT so I cannot go through this route, I was assuming I would simply be able to use the server name and name of the printer but this is proving harder than I first thought...

Thanks,
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17978851
Possible work around is for u to go to your printers, right click and select sharing, then just go thru the wizard.

now try the copy

copy yourfile.prn \\yourcomputername\sharename /b

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17979060
A viewer for PRN files, well there is something called GSView (http://www.cs.wisc.edu/~ghost/gsview/) that may help you, but that is for Ghostscript. Your PRN could be a windows file print of some other file or something,  so its hard to say, GSView probably wont help you if file type is not always the same.

Regarding the code, I gave u the DOS way and since u cant use DOS, I guess FileCopy instead of Copy is what u need to do.

0
 
LVL 2

Author Comment

by:generali
ID: 17979092
Hi Rocki,

The printer is set to share, I have tried what you have asked and it says "Path not found", what is the " /b" part at the end, what does this do?

thanks
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 250 total points
ID: 17979219
Howdo
alas, is it because its a network printer?

Have u tried specifying the full path?

/b is binary copy (dos)

I got it to successfully work in vba

copy "myfile.prn", "\\mynetworkfoldername\myprinters_sharename"  /b


but I cant get this to work using FileCopy

0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 65

Expert Comment

by:rockiroads
ID: 17979322
With DOS not available, does that mean, u cant create dos batch scripts on the fly (via vba) then execute them?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17979675
ok, one other method, now Im not sure if this will work with binary files, it works fine with txt files, is to code your own file copy. I know for sure that a file copy works fine when printing prn files manually

but FileCopy itself does not work as it seems to expect a valid filename


eg

Public Sub PrintNF()

    Dim sLine
   
    Dim iRead As Integer
    Dim iRite As Integer
   
    iRead = FreeFile
    Open "c:\myprnfile.prn" For Input As #iRead
   
    iRite = FreeFile
    Open "\\mynetworkname\myprintername" For Output As #iRite

    Do While EOF(iRead) = False
        Line Input #iRead, sLine
        Print #iRite, sLine
    Loop
   
    Close iRead
    Close iRite
End Sub



Now u can specify opening files as binary, certainly the open call to the printer has worked fine as it stands now
eg of opening binary files

    Open "c:\myprnfile.prn" For Binary Access Read As #iRead



I guess u can now parameterise this

apologies for my spelling of write!

0
 
LVL 2

Author Comment

by:generali
ID: 17979863
Thanks Rocki,

I created a batch file and it worked perfect, thanks! I'm going to try your file copy code too, as this may be quicker and Im intrigued as to how it works, Ill let you know the outcome..

Thanks again,

Matt
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17980085
If the batch file works then that means u have access to dos, surely
0
 
LVL 2

Author Comment

by:generali
ID: 17980243
I created a new bat file with command.com and it worked, but it doesn't when selected from the cmd... obviously a loophole
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17980409
ha!

its like with a certain financial institution

it does not allow certain file types via email, even if u zipped it

however, if u zip it with a password, then u zip that zip file (no password)
that gets thru their system
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Power PDF (http://www.nuance.com/for-business/document-imaging-and-scanning/power-pdf-converter/index.htm) is the newest product from the Document Imaging division of Nuance Communications (http://www.nuance.com/). It is available in two editions — …
In a previous article here at Experts Exchange (http://www.experts-exchange.com/articles/18414/Create-a-PDF-file-with-Contact-Sheets-montage-of-thumbnails-for-all-JPG-files-in-a-folder-and-each-of-its-subfolders-using-an-automated-batch-method.html)…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now