Computing.Net > Forums > Programming > Mail Merge using VB

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Mail Merge using VB

Reply to Message Icon

Name: olidav911
Date: October 13, 2006 at 06:58:06 Pacific
OS: N/A
CPU/Ram: N/A
Product: N/A
Comment:

I am working on making a mail merge. It basically picks data off excel as you expect it to do but I need to create a macro that'll open up every row in a new document. The coding I have done so far is:-

Sub Macro1()
Dim Counter As Integer
Counter = 1

Windows("Mail Merge Doc.doc").Activate
ActiveDocument.MailMerge.DataSource.ActiveRecord = 1
Selection.WholeStory
Selection.Copy
Documents.Add DocumentType:=wdNewBlankDocument
Selection.Paste
Do While Counter <= 7
Counter = Counter + 1
Windows("Mail Merge Doc.doc").Activate
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
Selection.WholeStory
Selection.Copy
Documents.Add DocumentType:=wdNewBlankDocument
Selection.Paste
Loop

End Sub

I need it to loop until it reaches the last row in the spreadsheet but how do I do this?



Sponsored Link
Ads by Google

Response Number 1
Name: pingy
Date: October 28, 2006 at 09:30:41 Pacific
Reply:

As I remeber correctly, the property UsedRange (i.e. Activesheet.UsedRange) contains the range of the last cell.
From this you can extract the last row.

You could allso loop until you find and empty row en use "Exit Do":

Do While True
If Emptyrow Then
Exit Do
End If
Do your stuff
Loop

You have to fill in "EmptyRow" yourself because I don't know what your Excelsheet looks like.

On the other hand, can't you get it done from Word? Create a mailmerge template in which you select the Excel file/sheet as the source and link the fields to the cells?


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Mail Merge using VB

macro help(mail merge file save) www.computing.net/answers/programming/macro-helpmail-merge-file-save/6062.html

MS Access mail merge to MS Word www.computing.net/answers/programming/ms-access-mail-merge-to-ms-word/7235.html

Opening Word Mail Merge from Access www.computing.net/answers/programming/opening-word-mail-merge-from-access/2345.html