Vba To Print Selected Records S’abonner

0
Avatar
Legacy Poster

What VBA code should I use to print only selected records from an excel file?

4 commentaires

0
Avatar
Domingo Rodriguez
Modérateur
Actions pour les commentaires Permalien

Do you mean that at print time, you want to set which database records you would like to print by automating BarTender via either ActiveX Automation or the .NET SDKs?

 

If yes, find below a code example which shows you how to do this (in VB.NET):

 

 

'Declare a BarTender application variable

Dim btApp As BarTender.Application

 

'Declare a BarTender document variable

Dim btFormat As New BarTender.Format

 

'Create a new instance of BarTender

btApp = New BarTender.Application

 

'Set the BarTender application visible

btApp.Visible = True

 

'Open a BarTender document

btFormat = btApp.Formats.Open("c:\Format1.btw", False, "")

 

'Set the RecordRange property

btFormat.RecordRange = "1-3,5(2),6"

 

'Print the document

btFormat.PrintOut(False, False)

 

'End the BarTender process

btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges)
 

0
Avatar
Legacy Poster
Actions pour les commentaires Permalien

Thanks Domingo,

 

Is there a way so every time I run the macro it selects the first 10 records, then the next 10, then the next 10, and so forth until getting to a fixed number, let's say 100?

0
Avatar
Legacy Poster
Actions pour les commentaires Permalien

So I developed this code, and it prints, but it's not selecting the ranges that I am indicating. I am not sure why. Please help..

 

Private Sub CommandButton1_Click()
    Const adder As Integer = 5
    Const maxIndex As Integer = 1553

Dim btApp As BarTender.Application
Dim btFormat As BarTender.Format

Dim index As Integer
Dim stringer As String
Dim first As Integer
Dim second As Integer

Set btApp = New BarTender.Application
Set btFormat = New BarTender.Format

btApp.Formats.Open ("K:\BINS\totes forecast2013.btw")

btApp.Visible = True

btApp.ActiveFormat.IdenticalCopiesOfLabel = 2

index = Sheet1.Cells(5, 4).Value + adder
first = Application.WorksheetFunction.Min(index, maxIndex)
second = Application.WorksheetFunction.Min(index + adder - 1, maxIndex)
stringer = (first & "-" & second)
btFormat.recordrange = stringer
If second >= maxIndex Then index = 1 - adder
Sheet1.Cells(5, 4).Value = index
 
btFormats = btApp.ActiveFormat.PrintOut(False, False)
 
 

End Sub

0
Avatar
Domingo Rodriguez
Modérateur
Actions pour les commentaires Permalien

I see that when opening the BarTender document, you're not assigning it to your btFormat variable, such as the example I sent you does:

btFormat = btApp.Formats.Open("c:\Format1.btw", False, "")

 

Is there perhaps where your problem lies?

 

I also see that you use the ActiveFormat for setting the number of identical copies and for printing, but you don't use this for the record range...

Vous devez vous connecter pour laisser un commentaire.