Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to Run every row of a Table with a Macro

Hi everyone, I'm trying to create a macro to display a Email for every row of a Simple Table of a specific Sheet. The numbre of row of this table and therefore the number of "my" different records is set by some List boxes placed in the same Sheet.

Let's say I have the SHEET1 with a TABLE (ID: CH01) with 3 columns: DeliveryNote, Customer, Email.

When I push the button I want to display an email for every row even when the values of the Columns Customer and Email may repeat.

I already know how to create the emails, but what I don't know is how to run the current data (rows of the table) and give thah values to the variables.

I've tried with this code:


Set Mails=ActiveSheet.Fields("CustVend").GetPossibleValues
Set CustomerName = ActiveDocument.Fields("Albaranes_Venta.NombreCliente").GetPossibleValues

Set AlbVenta=ActiveDocument.Fields("Albaranes_Venta.Nº Albarán").GetPossibleValues
' The Loop Begins
For i=0 to AlbVenta.Count-1
'We Create the Emails
Set vOutlook = CreateObject("Outlook.Application")

Set vMessage = vOutlook.CreateItem(olMailItem)
vMessage.Subject =

"Albarán Nº-" & AlbVenta.Item(i).Text & "-" & CustomerName.Item(i).Text


vMessage.To = xxxx@gmail.com
vMessage.HTMLBody = "Customer, I Attache a PDF of Delivery Note Nº " & AlbVenta.Item(i).Text
vMessage.Display
vMessage.Save
Next i




But I v



4 Replies
Not applicable
Author

Hi,

use table cells instead of list box.

Try

set table = ActiveDocument.GetSheetObject( "CH01" )

for RowIter = 1 to table.GetRowCount-1
vDeliveryNote=(table.GetCell(RowIter,0).text)
vCustomer=(table.GetCell(RowIter,1).text)
vEmail=(table.GetCell(RowIter,2).text)

'''' SEND MAIL

Next

Not applicable
Author

Ok thanks, it works, and do you know how I can store all the values of the DeliveryNOte Field in a Array to use them then one by one?

Regards.

llauses243
Creator III
Creator III

Hi Pedro & Alex,

Left script with your 2 macros adapted to case

Good luck

/Luis

Not applicable
Author

Hi Ilauses and do you know how I can store all the values of the DeliveryNOte Field in a Array to use them then one by one?