Marco doesn't show up when using Alt-F8

Status
Not open for further replies.

Michiel

New Member
Outlook version
Outlook 2013 64 bit
Email Account
IMAP
I found a nice script on slipstick website by Diane. Unfortunately I cannot get them to run. I am a bit new at VBA. I want to use the script Reply to a web form generated message. I already have some macros that work. In ThisOutlookSession I have pasted the code above below the other macros. The name SendNew shows up in the right corner where the name of the macros are displayed. But when I save, it doesn't show up when I hit Alt-F8. When I remove Item As Outlook.MailItem from between the brackets, the name SendItem does show up when I hit Alt-F8, but there is an error 424 in the script now. So a bit of a catch 22. I would love some advice on how to solve this. I have googled quite a bit...
This same issue, that a name of a script that I download from the internet shows up in the right top corner, but when I save, it doesn't show up when I hit Alt-F8, happens frequently, so there is something basic there that I don't understand.
The script from Diane:

Sub SendNew(Item As Outlook.MailItem)
Dim Reg1 As Object
Dim M1 As Object
Dim M As Object
Dim strAddress As String

Set Reg1 = CreateObject("VBScript.RegExp")

With Reg1
.Pattern = "(([\w-\.]*\@[\w-\.]*)\s*)"
.IgnoreCase = True
.Global = False
End With

If Reg1.Test(Item.Body) Then

Set M1 = Reg1.Execute(Item.Body)
For Each M In M1
strAddress = M.SubMatches(1)
Next
End If

Dim objMsg As MailItem
Set objMsg = Application.CreateItemFromTemplate("C:\path\to\template.oft")

objMsg.Recipients.Add strAddress

' Copy the original message subject
objMsg.Subject = "Thanks: " & Item.Subject

' use for testing
objMsg.display

' objMsg.Send

End Sub

 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This part: Sub SendNew(Item As Outlook.MailItem) means it needs to be called by another macro (or a run a script rule). If you remove the mailitem part, you need to set the item in the macro.

This should work to call the macro for the selected item. If you want it to work with open or selected items, get the function from Outlook VBA: Work with Open Item or Selected Item and use
Set Item = GetCurrentItem()

if you want to use 1 macro, you need to add the dim and set to the original macro (and remove the item as mailitem part)

Code:
sub runmacro()
Dim Item As Outlook.MailItem

Set Item = Application.ActiveExplorer.Selection.Item(1)

SendNew Item
end sub
 

Michiel

New Member
Outlook version
Outlook 2013 64 bit
Email Account
IMAP
Hi Diane,
The first part of your explanation I didn't quite follow, but the last part worked for me. :) I pasted your code below the original code, deleted the text between the brackets and works like a charm. Thank you!
 
Status
Not open for further replies.
Top