I've got a W2K template that generates a summary of selected documents.
The user is presented with a list box to choose which items are to be
summarized. I also want to send the selected documents as Outlook
e-mail attachments. I use this to start the e-mail (In the Userform
initialization)

Private Sub UserForm_Initialize()
~
mailtxt = "Assessments done " + Format(Now(), "mm/dd/yyyy")
Set maildas = CreateObject("Outlook.Application")
Set mailmsg = maildas.CreateItem(olmailItem)
With mailmsg
.To = "ASSEMAIL"
.Subject = mailtxt
.body = mailtxt
End With
End Sub

Then this to add the attachment (runs after the doc is summarized)

~
attdoc=ActiveDocument.FullName
mailmsg.Attachments.Add attdoc, olByValue, atpos, "document"
~

The code runs without an error, but the attachment isn't in the e-mail.
Any ideas? I do have a ref to the Outlook reference library.

Re: Attachment not appearing. by Doug

Doug
Wed May 24 15:13:57 CDT 2006

ActiveDocument.FullName should return the name of the activedocument.

As a test, add the following command:

mailmsg.Display

after

mailmsg.Attachments.Add attdoc, olByValue, atpos, "document"

and see if the attachment appears.
--
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

<acjharms@us-state.osis.gov> wrote in message
news:1148498390.209198.85760@j73g2000cwa.googlegroups.com...
> I've got a W2K template that generates a summary of selected documents.
> The user is presented with a list box to choose which items are to be
> summarized. I also want to send the selected documents as Outlook
> e-mail attachments. I use this to start the e-mail (In the Userform
> initialization)
>
> Private Sub UserForm_Initialize()
> ~
> mailtxt = "Assessments done " + Format(Now(), "mm/dd/yyyy")
> Set maildas = CreateObject("Outlook.Application")
> Set mailmsg = maildas.CreateItem(olmailItem)
> With mailmsg
> .To = "ASSEMAIL"
> .Subject = mailtxt
> .body = mailtxt
> End With
> End Sub
>
> Then this to add the attachment (runs after the doc is summarized)
>
> ~
> attdoc=ActiveDocument.FullName
> mailmsg.Attachments.Add attdoc, olByValue, atpos, "document"
> ~
>
> The code runs without an error, but the attachment isn't in the e-mail.
> Any ideas? I do have a ref to the Outlook reference library.
>



Re: Attachment not appearing. by acjharms

acjharms
Wed May 24 15:37:17 CDT 2006

Thanks, but so far, I've

--.Displayed mailmsg both before and after the Attachments.Add No
luck.
-- replaced attdoc with a filename (C:\test.doc). No joy.
-- If I replace attdoc with a filename that doesn't exist, I get an
error--System can't find filename specified (Whoopie, I know the code's
running!)

I'm wondering if starting the mailmsg in the Intialize sub and then
accessing it in another (both subs in the Userform) may be the issue.
I use pretty much identical code in a single sub in another macro and
it works fine there. I declare mailmsg as a public Object at the start
of the Module.


Re: Attachment not appearing. by Doug

Doug
Wed May 24 16:42:06 CDT 2006

Splitting the routine like that is quite likely the cause of the problem. I
can't imagine that you really need to start the process in the initialise
event of the user form.

--
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

<acjharms@us-state.osis.gov> wrote in message
news:1148503037.357711.74730@y43g2000cwc.googlegroups.com...
> Thanks, but so far, I've
>
> --.Displayed mailmsg both before and after the Attachments.Add No
> luck.
> -- replaced attdoc with a filename (C:\test.doc). No joy.
> -- If I replace attdoc with a filename that doesn't exist, I get an
> error--System can't find filename specified (Whoopie, I know the code's
> running!)
>
> I'm wondering if starting the mailmsg in the Intialize sub and then
> accessing it in another (both subs in the Userform) may be the issue.
> I use pretty much identical code in a single sub in another macro and
> it works fine there. I declare mailmsg as a public Object at the start
> of the Module.
>



Re: Attachment not appearing. by acjharms

acjharms
Thu May 25 11:02:39 CDT 2006

AARRGGGHH!! Now I need to call building maintenance. There's a hole in
the wall where I slammed my forehead.

Compacted the code into a single location in the macro. Still no joy.
Decided to start over, so I did a search on mailmsg in the code so I
could strip it out and....FOUND THE CODE CREATING THE MSG IN AUTONEW
(problem w/ going away for a week in the middle of a project). Removed
that version, some additional tweaks.and I'm good to go. Thanks for
the assist.