mihaibanro
12-09-2009, 03:09 AM
Hello, I am new in this forum.
I have a problem with a macro that I want to build. I search on internet and didn't find anything to help (I am also relatively new to VBA).
I want to mail merge from an excel data base to a form that I have made in Word (I use Microsoft Office 2007) and after that when I push a buton I want to print all record that contains in one merge field a certain value. I have made a macro that search every record and compare the value from the merge field with one that I want and give the result "OK" or "Not OK", but because I have a lot of record it works very slow (I know it because I have change the macro with that prints the records or skip the one that not meet the criteria).
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdLastRecord
NrInregistrari = ActiveDocument.MailMerge.DataSource.ActiveRecord
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord
For i = 1 To NrInregistrari
If InStr(1, ActiveDocument.MailMerge.DataSource.DataFields("Tip_medicament").Value, "T") > 0 Then MsgBox ("ok") Else MsgBox ("not ok")
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
Next i
Also, I think that is not the correct answer because when I sent to printer the records make different print jobs....I have tried to record macro and filter records that meet a criteria but when I have stop the record I didn't see anything in the macro....
Please anyone can help me....
Thanks
I have a problem with a macro that I want to build. I search on internet and didn't find anything to help (I am also relatively new to VBA).
I want to mail merge from an excel data base to a form that I have made in Word (I use Microsoft Office 2007) and after that when I push a buton I want to print all record that contains in one merge field a certain value. I have made a macro that search every record and compare the value from the merge field with one that I want and give the result "OK" or "Not OK", but because I have a lot of record it works very slow (I know it because I have change the macro with that prints the records or skip the one that not meet the criteria).
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdLastRecord
NrInregistrari = ActiveDocument.MailMerge.DataSource.ActiveRecord
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord
For i = 1 To NrInregistrari
If InStr(1, ActiveDocument.MailMerge.DataSource.DataFields("Tip_medicament").Value, "T") > 0 Then MsgBox ("ok") Else MsgBox ("not ok")
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
Next i
Also, I think that is not the correct answer because when I sent to printer the records make different print jobs....I have tried to record macro and filter records that meet a criteria but when I have stop the record I didn't see anything in the macro....
Please anyone can help me....
Thanks