Long story short, I helped a coworker create a macro to print 100+ .pdfs from a excel template controlled by a combobox he created using the Control Toolbox bar, so I believe it's ActiveX.
I looked around online to figure out how to control the combobox so it would loop through the selections, but for the life of me I can not get .ListIndex to work. So I wasn't sure if it only works with a Forms ComboBox, or how I would control the ActiveX combobox?
I did it the "ugly" way by just changing the linked cell to the value in the table as I looped through, but I would also like to learn how to use ListIndex for the future.
The commented out line is my attempt at .ListIndex. I tried a few other methods that I found online using Me., Shapes and Dropdown("ComboBox1"), etc. but none of them seemed to work.
Sub Print_Agents()
Dim lCount As Long
Dim wbComp As Workbook
Dim wsComp As Worksheet
Dim tempPDFFileName As String
Dim tempPSFileName As String
Dim tempPDFRawFileName As String
Dim tempLogFileName As String
Dim mypdfDist As New PdfDistiller
Set wbComp = ThisWorkbook
Set wsComp = wbComp.Sheets("SummaryAgt")
For lCount = 1 To wsComp.Range("T6", wsComp.Cells(Rows.Count, "T").End(xlUp)).Rows.Count
'wsComp.ComboBox1.ListIndex = lCount - 1
wsComp.Range("U3").Value = wsComp.Range("W" & lCount + 5).Value 'Workaround I used to control the ComboBox
tempPDFRawFileName = "G:\Budgets\Budget Finance\Financial Analysis\Compensation Plans\Texas FSU ProPay II\" & Right(Replace(wsComp.Range("C2").Value, ",", ""), Len(wsComp.Range("C2").Value) - 4)
tempPSFileName = tempPDFRawFileName & ".ps"
tempPDFFileName = tempPDFRawFileName & ".pdf"
tempLogFileName = tempPDFRawFileName & ".log"
wsComp.PrintOut Copies:=1, preview:=False, ActivePrinter:="Adobe PDF", _
printtofile:=True, Collate:=True, prtofilename:=tempPSFileName
mypdfDist.FileToPDF tempPSFileName, tempPDFFileName, ""
Kill tempPSFileName
Kill tempLogFileName
Next lCount
Set mypdfDist = Nothing
End Sub
Bookmarks