Hello excel gurus,
Today, I'm in need of some code tweaking to print out envelopes based on the selection from a list box. I have created code to do this but as is my luck, it doesn't seem to want to work. As you'll see in the code, I'm trying to call the word.application / word.document procedure. The user will select as few as 1 line in the listbox to as many as all lines to print envelopes. I will actually need to do this with 2 different size envelopes but that will be 2 separate procedures. If I can one to work, I'm confident I can tweak it to work for the other. This code below uses a "Size 12" envelope and the second would have a "Size 14" envelope. Which procedure (envelope size ) that is used will be determined by which check box is marked as "True". I will eventually, before shipping, enable or disable one or the other of the check boxes based on the selection. Below you will find the code I created. I will also upload a small sample book for testing. I will do my best to answer any and all questions regarding my needs and As always, thank you for the help and I look forward to reading your replies.
Private Sub cmbtnPrint_Click() Dim otable As Range, r As Long, c As Long, sAddr As String Dim oWord As Word.Application, oDoc As Word.Document Set oWord = CreateObject("Word.Application") Set oDoc = oWord.Documents.Add If Me.ckbxAbsenteeBallot = True Then 'With ListBox1.List(ListBox1.ListIndex) For r = 1 To Range("A10000").End(xlUp).Row If Cells(r, 1) = ListBox1.List(ListBox1.ListIndex) Then sAddr = Rows(r).Select oDoc.Envelope.PrintOut , sAddr, , , , , , , "Size 12" DoEvents: sAddr = "" End If Next r End If oWord.Quit False End Sub