Automatic email from word

E

Edgar

Hi

I am trying to write a macro to automatically send out
remittances to our clients when we have made a payment to
them.

The document is a new document that we create from Crystal
Reports. At the moment we are creating an HTML and sending
that out as an attachment. This is very time consuming as
I have to manually lookup email address (Which is on the
remittance advice) and the copy and paste text of email
message in.

I have tried writing a remittance for this but I cannot
find a way of copying the email address from the
remittance to the ‘send to’ field in Outlook. Is there a
way I can do this. Also I have a list of all email
address’s in a excel sheet with a reference to the
supplier id if this would help at all?

Many thanks for your help.
 
H

Helmut Weber

Hi Edgar,
hmm..., guess you are still on the wrong track.
You don't have to copy anything at all.
If you address Outlook programmatically, like:
....
Set oOutlookApp = GetObject(, "Outlook.Application")
Set oItem = oOutlookApp.CreateItem(olMailItem)
....
then all you have to do, is to find the address in the
doc or in the Excel-File or whereever, assign it to a
variable, like MyAddress$, and continue like this:
With oItem
.To = MyAddress$
.subject = MySubject$
.attachments.add activedocument.name
.send
End With
....
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, XP, NT4.0, W98
 
H

Helene Day

I had the same task to achieve and I get this error from Outlook when the
code is executed:

" A program is trying to automatically send e-mail on your behalf. Do you
want to allow this? If this is unexpected, it may be a virus and you should
choose "No". With Yes, No, Help buttons.

Is there a setting to prevent this dialog, or this comes from one of the
sercurity patch from MS?

Helene
 
H

Helmut Weber

Hi Edgar,
for a very simple approach,
imagine, there is a line like that in your doc:
EMail: (e-mail address removed)¶
You would then search for "EMail: ",
collapase the selection to the end,
switch to extend mode, search for chr$(13),
assign the selection.text to a variable,
MyAddress$ = selection.text
cut the paragraph mark off,
myaddress$ = left(myaddress$, len(myaddress$)-1)
and then:
..To = MyAddress$
You assign the variable to the ".to"-property
of the mail-item, not the other way round.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, W98
 
M

Michael Bednarek

I had the same task to achieve and I get this error from Outlook when the
code is executed:

" A program is trying to automatically send e-mail on your behalf. Do you
want to allow this? If this is unexpected, it may be a virus and you should
choose "No". With Yes, No, Help buttons.

Is there a setting to prevent this dialog, or this comes from one of the
sercurity patch from MS?

If you are running Outlook as an Exchange client, the following might help:

OL2000: Administrator Information About the Outlook E-mail Security Update
<http://support.microsoft.com/default.aspx?scid=kb;EN-US;263297>
 
M

Michael Bednarek

Sorry but how would i assign the email address to MyAddress?

How do you currently identify the e-mail address in your document? Is it in
a certain position, e.g. the second word of the fifth line on page 3? Or is
it formatted in a special way that no other text is formatted, e.g. font
colour blue, underlined? Or can it be identified by some constant and
unique text nearby? Is it the only text in the document which contains an
"@"-sign?

Once you identify the mechanics (if any) of your current manual approach it
will be trivial to implement them in VBA, usually by constructing a range.
The last step then is simply: myAddress = someRange
 

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