Printing to a DYMO LabelWriter 450 from VBA

I recently had to make some file folders at work. About five minutes after I was done, I purchased a DYMO LabelWriter 450. I was using one of those label makers where you punch in the text, hit print, and press down on a lever to cut the label. Then you have to take a pair of scissors and cut along the dotted line to get the right length. THEN you have to spend ten minutes fumbling with the backing. Brutal.

When I installed the software, it installed quite a few libraries. I wasn’t sure which one to pick, but after a little experimenting, I chose the Dymo Label Software v.8 SDK.

With my reference set, I tried a few different objects without much success. If there’s documentation for this, I haven’t found it. As usual, the object model leaves a lot to be desired. Nevertheless, I persevered and came up with this:

Sub TestLabel()
   
    Dim myDymo As DYMO_DLS_SDK.DymoHighLevelSDK
    Dim dyAddin As DYMO_DLS_SDK.ISDKDymoAddin
    Dim dyLabel As DYMO_DLS_SDK.ISDKDymoLabels
   
    Set myDymo = New DYMO_DLS_SDK.DymoHighLevelSDK
   
    Set dyAddin = myDymo.DymoAddin
    Set dyLabel = myDymo.DymoLabels
   
    dyAddin.SelectPrinter dyAddin.GetDymoPrinters
       
    dyAddin.Open Environ$(“USERPROFILE”) & “My DocumentsDYMO LabelLabelsBoardFile.label”
    dyLabel.SetField “Text”, “My text goes here”
    dyAddin.Print2 1, True, 1
   
    Set myDymo = Nothing
   
End Sub

Let’s step through this and try to see what’s happening. I start with a DymoHighLevelSDK object – what an awful name. This object has two properties: DymoAddin (what an awful name) and DymoLabels. From what I can tell, DymoLabels is only one label, from which I can only conclude…wait for it…they gave it an awful name. I needed to create both the DymoAddin object and the DymoLabels object. I would have thought that I could get the current label from the DymoAddin object, but that doesn’t appear to be the case.

I set the printer I want to use using SelectPrinter and GetDymoPrinters. I guess if you have more than one Dymo printer, GetDymoPrinters returns some delimited string. But I only have one, so I don’t know. Either way, it’s stupid. I discovered that GetDymoPrinters returns my one printer, so I pass that to SelectPrinter and that seems to have worked.

Next I open my .label template file. There’s also an Open2 method, but I don’t know the difference. Am I done bashing the DYMO programmers yet? Not even close. If you have two Open methods, don’t freaking name them Open and Open2. Name them something understandable like Open and OpenPriorVersion.

I tried

<span class="vb"><span class="kw1">Set</span> dyLabel = dyAddin.<span class="kw1">Open</span>(etc...)</span>

but got a Type Mismatch error. As far as I can tell, when I call the Open method to the DymoAddin object, the DymoLabels object automatically becomes whatever was open. Idiotic.

My label has one object on it called “Text”, so the SetField method was pretty straight forward. It reminds me of Quickbooks in that there are few, if any, properties and everything is a method.

Finally I tried the Print method, but was rewarded with “Object doesn’t support this property or method.” One of my favorite errors. Out of desparation, I chose the Print2 method. I had to include a third argument for PaperTray, which is utterly ludicrous if you look at the LabelWriter 450. But it worked.

I wanted to set the ShrinkToFit property of the Textbox to TRUE, but I couldn’t figure out how to do it. It did it automatically because I set that “property” when I created the label template, but it would be nice to be able to set it in code.

If I had written the object model, my code would have looked like this:

Sub TestLabelNonJerkyWay()
   
    Dim myDymo As Dymo.Application
    Dim dyLabel As Dymo.DymoLabel
   
    Set myDymo = New Dymo.Application
    Set dyLabel = myDymo.Open(“FilePathandName”)
    myDymo.ActivePrinter = “Dymo 450″
   
    With dyLabel.Fields(“Text”)
        .ShrinkToFit = True
        .Text = “My text goes here”
    End With
   
    dyLabel.Print 1
   
    myDymo.Close
    Set myDymo = Nothing
       
End Sub

Anyway, this post should get a million hits. Or maybe it will just get 100% of the hits from the 12 people who care about this.

6 Comments

  1. Gordon says:

    I had to set up a job to print barcodes & text to some Dymo printers, I think exactly the same model, a couple of years ago so started playing around with their add-in.

    I ended up just setting a sheet’s page properties to fit the label and sending a formatted range to it, seemed easier that mucking about with an add-in that would have to be checked for and installed every time a new PC was used.

  2. Blair says:

    Thanks for sharing. Not only for this recipe, but more generally showing that it is possible to dive in blind & figure out a model like this without going nuts.

  3. Pete says:

    Sounds like time for a holiday! :-)

  4. Chris Rieckenberg says:

    I recently purchased Bartender application for printing barcode labels. It is very slick and plays well with Excel and databases.

  5. Charles says:

    I’m using twin turbo 450. Does anyone know how to programmically select which roll to print from? If one roll is out of paper, how can I tell it to print from the other roll?

  6. Hefo says:

    At Charles
    With the .print2 method you are Able to Select the tray
    0= roll One 1= Roll two

Leave a Reply