Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

vb mail merge

ResolvedVersion 2002/XP

Caspar has attended:
Excel VBA Intro Intermediate course

VB Mail Merge

Hopefully just a quick question:


When using VB with a mail merge, is there a standard way of saying

'execute this sub automatically as the merged document is brought up after the mail merge rather than waiting for a user to run it'?

RE: VB Mail Merge

Hi

Thanks for getting in touch. Assuming you start your mail merge process in Excel, where you usually start a macro with

sub MyMacro()

You should have something like this

Private Sub Workbook_Open()

To recreate this code you can go to your Project Explorer in the VBE, select the ThisWorkbook object, then over the top of your code are two drop-downs. In the first select Workbook, and the second Open.

I hope this helps.

Kind regards

Gary Fenn
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: VB Mail Merge

Thanks for your prompt response. I've had no difficulty with the drop downs and clicking, but the subsequent macros do not seem to run automatically when the merge output opens.


Should it be


Private Sub Workbook_Open()

End Sub

Sub MyMacro()

...

...

End Sub



or


'Private Sub Workbook_Open()' instead of the text 'Sub MyMacro()' and then End Sub?


RE: VB Mail Merge

Hi Caspar

Just to be clear, it should look like this:

Private Sub Workbook_Open()

...
<mail merge code goes here>
...

End Sub

Does that help?

Kind regards

Gary Fenn
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: VB Mail Merge

Thanks - I've taken a note of the answer and I'm happy for this call to be closed - I do have another question to follow, though.

Fri 8 Mar 2013: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Filtering Data in an Excel 2010 Worksheet

When you have an Excel Worksheet with masses of data, it's not going to be easy to sift through it. So, in order to view sections of data, you can use the filter tool. Select the cells you want to filter (no need to select the column headers), then click the Home tab on the Ribbon, click Sort and Filter (you will find this in the Editing Section) then click Filter.

You will now see arrows in the top row of all the columns. If you click on an arrow, it will give you some filtering options so you can sort your data into ''Smallest to Largest'' or ''Oldest to Newest'' and so on..

To turn off the filtering, go back to the Home tab and click the Filter button again.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.11 secs.