跳至主內容

搜尋

搜尋

Excel Vba Printing

評論

2 條評論

  • Avatar
    Legacy Poster

    If anyone is interested,

     

    I have figured it out finally.

     

    The new code looks like this in the if statement:

     

    If Range("B2").Value > 0 Then
            For i = 1 To Range("B2").Value
                LLI = WireLabelBox.LabelList.ListIndex
                btFormat.RecordRange = LLI + 1
                btFormat.RecordRange = btFormat.PrintOut & i
            Next i

     

    I was trying to print from selected records, but selected records only takes integers. Therefore I had to find the index of my own list and use those numbers, respective to each label in the list.

     

    I hope this helps for anyone needing this in the future.

    0
  • Avatar
    Legacy Poster

    For anyone interested this is my complete (and working) code:

     

    It allows a user to print specific labels, referenced from the Bartender records (which pull data in from a separate spreadsheet):

     

     

     

    Sub openSpecificLabel()
        Dim BarTender As Object
        Dim dirfile As String
            dirfile = "N:\Labels\BarTender Labels\OTIS Wire Label.btw"
        

       
        Dim btApp As BarTender.Application
        Dim btFormat As BarTender.Format
        Dim LLI As Integer
        
        Set btApp = New BarTender.Application
        btApp.Visible = False
        Set btFormat = btApp.Formats.Open(dirfile)
        On Error Resume Next
        

        'I want my information to be chosen from a combo box and LLI allows for adding items and

        'the .listindex will connect the respective labels to the record numbers in Bartender
        LLI = WireLabelBox.LabelList.ListIndex
       

        'this allows the bartender file I have to connect which label I have chosen within my own combo box

        'adding the +1 was necessary because I noticed starting on a .listindex alone will automatically start at 0

        ' i.e. if I want the first label in my drop down menu, its corresponding bartender record is 1

        btFormat.RecordRange = LLI + 1
       

        'this lets me force the amount of labels I want to be printed through an excel cell

        btFormat.PrintSetup.IdenticalCopiesOfLabel = Range("B2").Value
       

        'having btformat instead of activeformat allowed me to specifically print what I was changing around in Bartender within my code

        'and setting it equal to btformat.recordrange tells bartender to print that record that I have chosen through my drop down menu in excel

        btFormat.RecordRange = btFormat.PrintOut(False, False)
        
        btApp.Quit
        
    End Sub
     

    0

登入寫評論。