Attaching files to emails using a wildcard

A

Andrew@Telstra

To Whom it may concern,

I am using an Excel 2003 marco to create a number of emails, with attached
files. The files I am attaching follow a "format", are CSV type, and are
unique to the folder, but are not sequential, eg., CML_1234567.csv. I've
tried a few versions of the following code (without success);
.Attachments.Add (PathtoFile & strFileA & "CML" & "*" & ".csv")
&
.Attachments.Add (PathtoFile & strFileA & "CML" & "*.csv")

How can I use a "Wildcard" to select a file for attachment to an email?



TIA
Andrew from Telstra
 
G

Guest

Hi Andrew

Not sure if this is what you are after. It sounds like you are trying to
allow the user to select the file to attach to the email?

Taken from the VBE help

fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
MsgBox "Open " & fileToOpen
End If

Ammend the above to your file type, and ammend the code to attach the file.
Apologies if this is not what you are after

HTH
 
A

Andrew@Telstra

Hello Steve,

Unfortunately, this is not entirely what I am looking for. I do not want
the user (me) to select the file to be attached to the email. I want the
macro to select the file to be attached to the email, and attach it. The
only thing that is consistant with the file's naming convention, is the
initial qualifier (CML), and the extension (.csv).

I have another macro that opens a file with a similar naming convention. In
that case, the file's name is Orderyyyymmddhhmmss (ie., date & time). Since
the time is variable, I use the astericks as a wildcard to open the file;
Workbooks.OpenText Filename:= PathToFile & "Order" & FileDate & "*"

This code works very well, and I thought that Excel's VBA would allow me to
use a version of it to attach semi-consistant files to emails.

Are you able to shed more light on my problem?


TIA
Andrew from Telstra
 
A

Andrew@Telstra

Hello Steve,

You're right: the problem is making the macro know what specific file it
needs to attach. I've copied the code to the macro, because I like the idea
of using the same code to create many different emails. So I'll have a good
look at it. I'm sure if I take it slowly, I'll understand what's happening.
And if I discover how to attach the files, I'll let you know.

Thanks
Andrew from Telstra.
 

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