Mail Merge to HTML

Jon Kelly

Board Regular
Joined
Jul 7, 2005
Messages
55
I am trying to write a macro to automatically create html documents from a mail merge document which is reading data from an Access database. I have succesfully written the following code:

Sub Macro2()
'
ChangeFileOpenDirectory _
"\\Your-axy8yb6izy\jon kelly\My Documents\Alpine Winters Website\public_html\resorts\france\les_gets\"

ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord

For i = 0 To 5

ActiveDocument.SaveAs FileName:="chalet" & i & ".html", FileFormat:=wdFormatText, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False, Encoding:=1252, InsertLineBreaks:=False, AllowSubstitutions:=False _
, LineEnding:=wdCRLF

ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord

Next

End Sub


However I still have two problems:

1. I would like to count the number of records in the intitial Access Query so that I can set the For....Next loop to this number.

2. I would like to set the filename to one of the fields in the query.

Can anybody help.

Jon Kelly
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,224,844
Messages
6,181,291
Members
453,030
Latest member
PG626

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top