 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Martin Guest
|
Posted: Mon Aug 07, 2006 9:05 pm Post subject: Word Mail Merge to Email |
|
|
I am trying to automate a mail merge to email and can't understand why my
code isn't working. Looking at the VB code from the automation help, and by
recording a macro in word I am sure I am doing everything I should, but I
just can't get it working.
I am running Delphi 5, Word 2002 SP3, Word2000.pas and email client is
Eudora 7
All works perfectly if I run by hand from Word. Any suggestions gratefully
received as this is driving me mad. There is a snippet of my code below,
procedure TComWord.MailMergeToEmail(Template, Datasource: string);
.....
{Open template}
if not WordVisible then
WordVisible := True;
ovFalse := False;
if OpenDoc(Template,False,False, result) then
begin
{make current doc a mail merge to email doc}
result.MailMerge.Set_MainDocumentType(TOleEnum(wdEmailMessage));
result.MailMerge.Set_SuppressBlankLines(true);
result.MailMerge.Set_Destination(wdSendToEmail);
{open data source}
_MailMergeOpenDataSourceForEmail(DataSource, result);
{and merge}
result.MailMerge.Set_MailAddressFieldName('Emailxx');
result.MailMerge.Set_MailSubject('Test Mail');
if result.MailMerge.State = wdMainandDataSource then
result.MailMerge.Execute(ovFalse)
end
.....
and a couple of the called procedures....
function TComWord.OpenDoc(sFile : string; bReadOnly, bAddToMRU : boolean;
var oOutDoc : _Document) : boolean;
A Wrapper for a documents.open(...) call
procedure TComWord._MailMergeOpenDataSourceForEmail(
const DataSource: string; oTemplate: _Document);
Just a wrapper for a call to MailMerge.OpenDataSource |
|
| Back to top |
|
 |
Martin Guest
|
Posted: Mon Aug 07, 2006 9:36 pm Post subject: Re: Word Mail Merge to Email |
|
|
Sorry, I didn't say did I.
The template opens, there are no errors and I step through the execute and
nothing happens - no mails queued. Makes no difference whatever value I use
for MainDocumentType (a '4' changes it to emailMessages, using
wdEmailMessage changes it to Formletters but this still works running by
hand) the state of the template changes correctly as the data source is
opened, the destination is correctly showing as 2 (wdSendtoemail) if I stop
the process before the execute and click the merge to email buttom in Word,
my subject and amail address field are correctly set and the merge works
fine.
If you want fuller source (I posted snippets from a Big com wrapper
component that we use for mail merges and lots of other Word COM document
processes) let me know and I'll zip some code up.
Thanks in Advance for any suggestions..
"Deborah Pate (TeamB)" <d.pate (AT) blueyonder (DOT) co.not-this-bit.uk> wrote in
message news:VA.000020ee.01067d53 (AT) blueyonder (DOT) co.not-this-bit.uk...
|
|
| Back to top |
|
 |
Deborah Pate (TeamB) Guest
|
Posted: Mon Aug 07, 2006 10:21 pm Post subject: Re: Word Mail Merge to Email |
|
|
<<Martin:
I am sure I am doing everything I should, but I
just can't get it working.
What goes wrong, exactly?
--
Deborah Pate (TeamB) http://delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html |
|
| Back to top |
|
 |
Deborah Pate (TeamB) Guest
|
Posted: Mon Aug 07, 2006 11:34 pm Post subject: Re: Word Mail Merge to Email |
|
|
<<Martin:
my subject and amail address field are correctly set and
the merge works fine.
Hm, that knocks out one theory. Does the merge work if
you set the destination to wdSendToNewDocument instead of
email?
(FWIW something like your code works fine here, with Word
2000 and Outlook.)
--
Deborah Pate (TeamB) http://delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html |
|
| Back to top |
|
 |
Martin Guest
|
Posted: Tue Aug 08, 2006 1:36 pm Post subject: Re: Word Mail Merge to Email |
|
|
Deborah,
Thanks very much for looking at this, I have a feeling that it might be to
do with the mail format not setting correctly, seems to default to HTML
rather than Plain Text though I set wdFormatText (perhaps unicodeText will
sort it out) I'll play a bit more with it this aternoon, I'll also test the
code with outlook as my default rather than Eudora as I am having a few
problems with other email calls to Eudora since upgrading to Eudora 6.1 (bcc
parameter strings being placed into the subject ???) but that is another
issue.
Martin. |
|
| Back to top |
|
 |
Martin Guest
|
Posted: Wed Aug 09, 2006 9:48 pm Post subject: Re: Word Mail Merge to Email |
|
|
Deborah, I have finally sorted this. My problem was that I was using Word
2002 with Word 2000. By importing word_tlb, rewriting loads of library code
to use the new xxxx2000 calls where required, I could then set the new
MailFormat property when running with Word 2000
(Set_MailFormat(wdMailFormatPlainText)) and all runs smoothly.
Thanks very much for looking at this,
Martin.
"Deborah Pate (TeamB)" <d.pate (AT) blueyonder (DOT) co.not-this-bit.uk> wrote in
message news:VA.000020ef.01497109 (AT) blueyonder (DOT) co.not-this-bit.uk...
| Quote: | Martin:
my subject and amail address field are correctly set and
the merge works fine.
Hm, that knocks out one theory. Does the merge work if
you set the destination to wdSendToNewDocument instead of
email?
(FWIW something like your code works fine here, with Word
2000 and Outlook.)
--
Deborah Pate (TeamB) http://delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|