PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook VBA Programming getting new button to work with wordmail

Reply

getting new button to work with wordmail

 
Thread Tools Rate Thread
Old 04-12-2007, 09:29 AM   #1
Robin
Guest
 
Posts: n/a
Default getting new button to work with wordmail


Hi
I have a macro that I have linked to a customized button (code below). It
effectively sends the email to a sub-folder in the sent items called "Temp
Sent". I would like to use Word as my editor, but this does not work. I
changed the email editor to Word 2003, opened a new email, added a new button
which is linked to this macro but Outlook does not like this (error: "compile
error, user defined type not defined"). Have I gone about this the wrong way
or is there a way of fixing this?

Public Sub SendAndDelete()

Dim objFolder As Outlook.MAPIFolder
Dim oSent As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace
Dim obj As Object
Dim Mail As Outlook.MailItem

Set obj = Application.ActiveInspector.CurrentItem
Set Mail = obj
Set objNS = Application.GetNamespace("MAPI")
Set oSent = objNS.GetDefaultFolder(olFolderSentMail)
Set objFolder = oSent.Folders("Temp Sent") 'Assume this is a mail folder

Mail.Move objFolder

Mail.Send

Set objFolder = Nothing
Set oSent = Nothing
Set objNS = Nothing

End Sub

Thanks a ton...

  Reply With Quote
Old 04-12-2007, 01:16 PM   #2
Sue Mosher [MVP-Outlook]
Guest
 
Posts: n/a
Default Re: getting new button to work with wordmail

Since you're writing the macro in Word, it knows nothing about Outlook until you tell it. You must make these changes:

1) Add a reference to the Microsoft Outlook library.

2) Declare and instantiate an Outlook.Application object. In a Word macro context, Application is Word.Application, not Outlook.Application.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Robin" <Robin@discussions.microsoft.com> wrote in message news:23C32D09-CB54-4BC9-900D-9D80E3F0CED7@microsoft.com...
> Hi
> I have a macro that I have linked to a customized button (code below). It
> effectively sends the email to a sub-folder in the sent items called "Temp
> Sent". I would like to use Word as my editor, but this does not work. I
> changed the email editor to Word 2003, opened a new email, added a new button
> which is linked to this macro but Outlook does not like this (error: "compile
> error, user defined type not defined"). Have I gone about this the wrong way
> or is there a way of fixing this?
>
> Public Sub SendAndDelete()
>
> Dim objFolder As Outlook.MAPIFolder
> Dim oSent As Outlook.MAPIFolder
> Dim objNS As Outlook.NameSpace
> Dim obj As Object
> Dim Mail As Outlook.MailItem
>
> Set obj = Application.ActiveInspector.CurrentItem
> Set Mail = obj
> Set objNS = Application.GetNamespace("MAPI")
> Set oSent = objNS.GetDefaultFolder(olFolderSentMail)
> Set objFolder = oSent.Folders("Temp Sent") 'Assume this is a mail folder
>
> Mail.Move objFolder
>
> Mail.Send
>
> Set objFolder = Nothing
> Set oSent = Nothing
> Set objNS = Nothing
>
> End Sub
>
> Thanks a ton...
>

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off