A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

getting new button to work with wordmail



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old December 4th 07, 10:29 AM posted to microsoft.public.outlook.program_vba
robin
external usenet poster
 
Posts: 53
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...

  #2  
Old December 4th 07, 02:16 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default 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" wrote in message ...
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...

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2007 Help Button doesn't work Stuart Krantz Outlook - Installation 1 March 12th 07 08:35 PM
Work with Headers Button Drasko Outlook - Installation 0 December 19th 06 02:36 PM
Cannot get option button to work... Tanya Lee Outlook - Using Forms 2 June 27th 06 05:25 PM
My reply button will not work seln Outlook - Installation 1 March 9th 06 04:06 AM
How to work with MailItems after pressing Send-Button Darius Add-ins for Outlook 5 January 20th 06 04:27 PM


All times are GMT +1. The time now is 09:22 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.