VBA to print to a label with certain size, every time, on a network printer

wbstadeli

Board Regular
Joined
Mar 11, 2016
Messages
153
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have a workbook that runs a macro to fill in a "label" which is just a separate worksheet within the workbook that is formatted to a certain label size. It also prints that "label" out to a Dymo label printer that is set up as a network printer. This all works great, except sometimes a default setting in our Dymo Label Printer will get changed, so when the macro is ran to print the label it prints the wrong size out and usually way to many labels because the print area is not correct. What can i put in my code so that it always checks/changes to the correct label size, and "landscape" orientation BEFORE it prints out? There are too many users and computers to go around and make sure everybody's default is set correctly. Could anyone help me out? Below is the code, thanks!

Also looking at the current code i have, is there a shorthand way to write the code pertaining the:
Code:
Const MyPrinter As String = "DYMO LabelWriter 450 Twin Turbo on Ne00:"
sCurrentPrinter = Application.ActivePrinter
On Error Resume Next

and all the other Ne options that it has to check?

Code:
Sub printlabel()


Dim sCurrentPrinter As String
Const MyPrinter As String = "DYMO LabelWriter 450 Twin Turbo on Ne00:"
sCurrentPrinter = Application.ActivePrinter
On Error Resume Next
Application.ActivePrinter = "DYMO LabelWriter 450 Twin Turbo on Ne01:"
sCurrentPrinter = Application.ActivePrinter
On Error Resume Next
Application.ActivePrinter = "DYMO LabelWriter 450 Twin Turbo on Ne02:"
sCurrentPrinter = Application.ActivePrinter
On Error Resume Next
Application.ActivePrinter = "DYMO LabelWriter 450 Twin Turbo on Ne03:"
sCurrentPrinter = Application.ActivePrinter
On Error Resume Next
Application.ActivePrinter = "DYMO LabelWriter 450 Twin Turbo on Ne04:"
sCurrentPrinter = Application.ActivePrinter
On Error Resume Next
Application.ActivePrinter = "DYMO LabelWriter 450 Twin Turbo on Ne05:"
sCurrentPrinter = Application.ActivePrinter
On Error Resume Next
Application.ActivePrinter = "DYMO LabelWriter 450 Twin Turbo on Ne06:"
sCurrentPrinter = Application.ActivePrinter
On Error Resume Next
Application.ActivePrinter = "DYMO LabelWriter 450 Twin Turbo on Ne07:"
sCurrentPrinter = Application.ActivePrinter
On Error Resume Next
Application.ActivePrinter = "DYMO LabelWriter 450 Twin Turbo on Ne08:"
sCurrentPrinter = Application.ActivePrinter
On Error Resume Next
Application.ActivePrinter = "DYMO LabelWriter 450 Twin Turbo on Ne09:"
sCurrentPrinter = Application.ActivePrinter
On Error Resume Next
Application.ActivePrinter = "DYMO LabelWriter 450 Twin Turbo on Ne10:"
sCurrentPrinter = Application.ActivePrinter
On Error Resume Next
Application.ActivePrinter = MyPrinter
Sheets("Label").PrintOut
Application.ActivePrinter = sCurrentPrinter
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi there:

I have a similar requirement, the code below will find your printer and return the full name:

Just put sCurrentPrinter = AAA to set sCuurentPrinter to the correct value.

Code:
    Function AAA()
        Dim Printers() As String
        Dim N As Long
        Dim S As String
        Printers = GetPrinterFullNames()
        For N = LBound(Printers) To UBound(Printers)
        If Left(Printers(N), 31) = "DYMO LabelWriter 450 Twin Turbo" Then
            AAA = Printers(N)
        Exit For
        End If
        Next N
        
    End Function

To set the parameters correctly, you could record a macro where you set everything manually and use the resulting (bloated) code.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top