Skip navigation


Here we will access a network printer and set it to a local port using visual basic codes.
This procedure is good for sending Escape Codes to a printer.
For this example you will use an escape codes for Epson printer.

'Dos command to set an network printer to LPT1
Call Shell("cmd /c net use lpt1 //SeverName/SharedName",vbHide)

'Set LPT1 as an output device to be able to print directly to LPT1
Open "LPT1:" For Output As #1

'Epson escape code for Master Select & Draft
Print #1, Chr(27) & Chr(33) & Chr(1)
Print #1, Chr(27) & Chr(120) & Chr(48)

Print #1, "Hello, greatxam"

'Epson escape code for Form Feed
Print #1, Chr(12)

'Close LPT1
Close #1

'Remove connection to printer
Call Shell("cmd /c net use lpt1 /delete",vbHide)

Note:
ServerName is the hostname or an ip address where the printer is installed.
SharedName is the Shared name of the printer you want to access in the network.
Advertisements

4 Comments

  1. I’m so glad I found this site…Keep up the good work

  2. i was searching this for tons of times ….. thanks for the Great Work

  3. this code did not work for me, it took hours to play with this, but i still successfully run it

    use this another way……. if net use lpt1 will not work for you, use this one simple but it worked for me
    iradicate the net use use thingy just directly open it thru your network

    Open “//serverName/sharedPrinter/LPT1:” For Output As #1

    ‘Epson escape code for Master Select & Draft
    Print #1, Chr(27) & Chr(33) & Chr(1)
    Print #1, Chr(27) & Chr(120) & Chr(48)

    Print #1, “Hello, greatxam”

    ‘Epson escape code for Form Feed
    Print #1, Chr(12)

    ‘Close LPT1
    Close #1

    • This is good, a different approach and it also work.
      Removing the call of shell from the process and directly opening the network printer.
      Great work. Thanks bossNai.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: