Jump to content

 

Hi everyone,

I need help automating a process to print labels directly from Excel. I’ve attached a picture of my file: https://ibb.co.com/DYdNr5H and these are the labels: https://ibb.co.com/S5SRtH5
it includes serial numbers, label names, quantities, and a "Print" button.

The idea is to embed PDF/JPG/PNG  in the Excel sheet or link them so that clicking "Print" automatically sends the corresponding label to the printer. This would save me tons of time compared to manually printing each label.

Questions:
‣ Is this a good approach, or should I consider another tool/software?
‣ Can Excel handle this efficiently, especially for many labels?

Looking forward to hearing your suggestions!

Link to comment
https://linustechtips.com/topic/1592411-excel-help/
Share on other sites

Link to post
Share on other sites

It's possible to do it, but I'm not sure it's the best way to do it, since it just sends a print command to whatever default printer you have selected in Windows. I fiddled with it a bit and found that you can invoke a VBA function by following a hyperlink. The formula in this case is

 

=HYPERLINK("#Print_Label()";"Print label")

 

The first parameter is the name of the function that gets called and the second parameter is the text that gets displayed in the cell. The script that runs once the link is clicked depends on the values relative to the position of the cell the link is clicked in. It basically just offsets the selection by two to the left to get the label name and by one to the left to get the quantity.

 

To make customization easy, I added the folder path in cell C2, which the code then references, so if you ever need to change it, it's easy to do.

 

image.png.990cc07652a5b8b5f02ab7478ad0afed.png

 

The folder with the files is laid out like this, again with the file names corresponding with the label name in the Excel sheet. That means adding a new file and a corresponding line in the table is pretty straightforward and should just work automatically, if you also copy the hyperlink into the new row.

image.png.abd29484d678d058b7c7f0373c232e98.png

 

Then you need to create a module in the VBA Editor (Alt+F11) and add this function in that module.

image.png.d097e7f460c593b0405c5c69596c0109.png

 

Function Print_Label()
    
    Set Print_Label = Selection
    
    Dim folder As String, fileName As String
    folder = ThisWorkbook.Sheets(1).Range("C2").Value
    fileName = Print_Label.Offset(, -2).Value & ".pdf"

    Dim quantity As Integer
    If Not IsNumeric(Print_Label.Offset(, -1).Value) Then
        MsgBox "Please enter a numeric value for the number of labels you wish to print."
        Exit Function
    Else
        quantity = Print_Label.Offset(, -1).Value
        If quantity < 1 Then Exit Function
    End If
    
    Static myShell As Object
    Dim i As Integer
    Set myShell = CreateObject("Shell.Application")
    
    For i = 1 To quantity
        myShell.Namespace(0).ParseName(folder & fileName).InvokeVerb "Print"
    Next i

End Function

And now a word from our sponsor: 💩

ℑ𝔣 𝔶𝔬𝔲 𝔬𝔫𝔩𝔶 𝔫𝔬𝔱𝔦𝔠𝔢 𝔭𝔢𝔯𝔣𝔬𝔯𝔪𝔞𝔫𝔠𝔢 𝔭𝔯𝔬𝔟𝔩𝔢𝔪𝔰 𝔴𝔥𝔢𝔫 𝔶𝔬𝔲 𝔥𝔞𝔳𝔢 𝔞 𝔰𝔱𝔞𝔱 𝔠𝔬𝔲𝔫𝔱𝔢𝔯 𝔬𝔳𝔢𝔯𝔩𝔞𝔶 𝔞𝔠𝔱𝔦𝔳𝔢, 𝔶𝔬𝔲 𝔞𝔯𝔢 𝔪𝔢𝔯𝔢𝔩𝔶 𝔩𝔬𝔬𝔨𝔦𝔫𝔤 𝔣𝔬𝔯 𝔭𝔯𝔬𝔟𝔩𝔢𝔪𝔰 𝔱𝔬 𝔟𝔢 𝔲𝔭𝔰𝔢𝔱 𝔬𝔳𝔢𝔯. 𝔗𝔲𝔯𝔫 𝔬𝔣𝔣 𝔱𝔥𝔢 𝔠𝔬𝔲𝔫𝔱𝔢𝔯 𝔟𝔢𝔣𝔬𝔯𝔢 𝔞𝔰𝔨𝔦𝔫𝔤 𝔣𝔬𝔯 𝔥𝔢𝔩𝔭 𝔞𝔫𝔡 𝔰𝔢𝔢 𝔦𝔣 𝔶𝔬𝔲 𝔰𝔱𝔦𝔩𝔩 𝔫𝔬𝔱𝔦𝔠𝔢.

-.-. --- --- .-.. --..-- / -.-- --- ..- / -.- -. --- .-- / -- --- .-. ... . / -.-. --- -.. .

ᑐᑌᑐᑢ

Spoiler

    ▄██████                                                      ▄██▀

  ▄█▀   ███                                                      ██

▄██     ███                                                      ██

███   ▄████  ▄█▀  ▀██▄    ▄████▄     ▄████▄     ▄████▄     ▄████▄██   ▄████▄

███████████ ███     ███ ▄██▀ ▀███▄ ▄██▀ ▀███▄ ▄██▀ ▀███▄ ▄██▀ ▀████ ▄██▀ ▀███▄

████▀   ███ ▀██▄   ▄██▀ ███    ███ ███        ███    ███ ███    ███ ███    ███

 ██▄    ███ ▄ ▀██▄██▀    ███▄ ▄██   ███▄ ▄██   ███▄ ▄███  ███▄ ▄███▄ ███▄ ▄██

  ▀█▄    ▀█ ██▄ ▀█▀     ▄ ▀████▀     ▀████▀     ▀████▀▀██▄ ▀████▀▀██▄ ▀████▀

       ▄█ ▄▄      ▄█▄  █▀            █▄                   ▄██  ▄▀

       ▀  ██      ███                ██                    ▄█

          ██      ███   ▄   ▄████▄   ██▄████▄     ▄████▄   ██   ▄

          ██      ███ ▄██ ▄██▀ ▀███▄ ███▀ ▀███▄ ▄██▀ ▀███▄ ██ ▄██

          ██     ███▀  ▄█ ███    ███ ███    ███ ███    ███ ██  ▄█

        █▄██  ▄▄██▀    ██  ███▄ ▄███▄ ███▄ ▄██   ███▄ ▄██  ██  ██

        ▀███████▀    ▄████▄ ▀████▀▀██▄ ▀████▀     ▀████▀ ▄█████████▄

 

Link to comment
https://linustechtips.com/topic/1592411-excel-help/#findComment-16597147
Share on other sites

Link to post
Share on other sites

6 hours ago, DeadShotAnk said:

‣ Is this a good approach, or should I consider another tool/software?

Probably not a great idea, if you must use excel for some reason then sure, otherwise I'd shift towards a python or even powershell script

6 hours ago, DeadShotAnk said:

‣ Can Excel handle this efficiently, especially for many labels?

As long as you're printing them one at a time as shown by @Avocado Diaboli it will probably be fine...? But certainly nowhere near as efficient as a small program doing the same thing. If you want to batch print hundreds or thousands of labels excel likely becomes inadequate.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
https://linustechtips.com/topic/1592411-excel-help/#findComment-16597219
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×