Doug's Attachment macro-handling empty cells

A

aeacsharp

Doug Robbins' tutorial and macro for merging with email attachments is
terrific -- thanks!

But in my case, I would like the macro to handle cases in which rows in
the "directory" word file are empty, moving on to the next row/record
email address. This case comes about because my directory has a fixed
number of columns, but the number of attachments in any row may vary,
from a minimum of 1, up to 10. My data source is an access table,
itself the result of a make-table query activated by a command button
on a form.

However, I do find the macro to work flawlessly when all the attachment
columns contain data with a valid path, with no empty cells.

Has anyone a suggestion for accomplishing what I want to do?

thanks!
 
A

aeacsharp

I;m sorry, i mis-stated something here:
"But in my case, I would like the macro to handle cases in which
**rows** in the "directory" word file are empty, moving on to the next
row/record "

for "rows" substitute the word "cells". I need help in handling empty
cells in the "directory" word file, so that the macro VB does not
"break" when an attachment path resolves to "".

my apologies!
 
D

Doug Robbins - Word MVP

The following modification to the code will check to see if there is a colon
in the cell, as there would be if it contains the path and filename of an
attachment, and only add the attachment if there is:

For i = 2 To Maillist.Tables(1).Columns.Count
Set Datarange = Maillist.Tables(1).Cell(Counter, i).Range
Datarange.End = Datarange.End - 1
If InStr(Datarange, ":") > 0 Then
.Attachments.Add Trim(Datarange.Text), olByValue, 1
End If
Next i


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

aeacsharp

Outstanding, thanks so much, Doug. Yes, it does help. Works great,
saved us all some time up here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top