Excel Vba Printing Follow

0
Avatar
Legacy Poster

Hey all,

 

I'm currently having an issue with my code in excel VBA.  It seems like it would be relatively easy, but I cannot figure out the solution.

 

It involves printing to Bartender from a combo box drop down list.  And while the list is working and shows my data, whatever code I seem to use prints all records of the database, rather than just the specific record that I have selected.

 

If there is someone who thinks they may be able to help me I would really appreciate it.  I was reading on the forums somewhere it might have to do with "activeformat" but there was never a continuation of how to fix it or if that was for sure the reasoning.

 

 

Here is my code:

 

Sub openSpecificLabel()
    Dim BarTender As Object
    Dim dirfile As String
        dirfile = "something"
    
    Dim btApp As BarTender.Application
    Dim btFormat As BarTender.Format
    
    Set btApp = New BarTender.Application
    Set btFormat = New BarTender.Format
    btApp.Visible = False
    btApp.Formats.Open (dirfile)
    On Error Resume Next
    
    If Range("B2").Value > 0 Then
        For i = 1 To Range("B2").Value
            btFormat.RecordRange = (WireLabelBox.LabelList)
            btFormat = btApp.ActiveFormat.Printout (false, false) & i
        Next i
        
        btApp.Quit
    Else
        btApp.Quit
    End If
End Sub

2 comments

0
Avatar
Legacy Poster
Comment actions Permalink

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
Comment actions Permalink

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
 

Please sign in to leave a comment.