Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chibeardia

macrumors newbie
Original poster
May 18, 2017
4
0
I have this successfully working in Outlook proper. I would like to convert it to apple script.


Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)


If TypeOf Item Is Outlook.MailItem Then

Dim olMsg As MailItem

Set olMsg = Item

Dim Prompt As String


Prompt = "***WARNING***" & vbNewLine & vbNewLine & _

"Do you want to CC this message to AVH?"


If MsgBox(Prompt, vbYesNo + vbQuestion, "CC AVH?") = vbYes Then

Set myRecipient = olMsg.Recipients.Add("Van Holsbeke, Ashley")

myRecipient.Type = olCC

myRecipient.Resolve

End If



Set olMsg = Nothing



End If


End Sub
 
It might be useful for others trying to help you to include the actual result of the VBA code. It looks like it does something to a mail message, pops up a message box, adds a name to recipients. Right? A good starting point would be to look at Outlook"s dictionary.
 
apologies...The purpose is to have a pop up to ask if the user would like to cc a specific address



Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) Call outlook


If TypeOf Item Is Outlook.MailItem Then

Dim olMsg As MailItem

Set olMsg = Item

Dim Prompt As String


Prompt = "***WARNING***" & vbNewLine & vbNewLine & _

"Do you want to CC this message to AVH?" popup that asks if you want to cc a specific user


If MsgBox(Prompt, vbYesNo + vbQuestion, "CC AVH?") = vbYes Then if yes is click add the below address to the email

Set myRecipient = olMsg.Recipients.Add("Van Holsbeke, Ashley")

myRecipient.Type = olCC

myRecipient.Resolve this calls for a resolve of the above user to the correct email/contact

End If



Set olMsg = Nothing



End If


End Sub
 
Hmmm. Am I right in thinking you're wanting to pop this up when a user tries to send an email? If so, I'm not sure if you can intercept an "mail send" event with AppleScript as appears to be possible with VBA.

Unless anyone else here knows differently?
 
Here is the popup from outlook.
 

Attachments

  • Capture.JPG
    Capture.JPG
    15.8 KB · Views: 272
Although I haven't done any VB coding for about 15 years, or indeed used Microsoft products for as long as well.

I think your misunderstanding the difference between VBA and AppleScript.
Although your VBA code can be interpreted into AppleScript code, this would not help you.

VBA code is used as an application extension or plugin to the host application, and uses an OLE automation mechanism, and is driven by Application Events, as opposed to AppleScript's system wide Apple Event mechanism.

Where as your VBA code module is almost part of the application's features, which could be run from the applications menu or toolbar, any AppleScript file would be an external script file, which would have to be double clicked or activated before it could perform any actions.

But I believe if memory serves me correct, you can create a VBA code module from within the Outlook application with this sort of code here.

Code:
#VB Code
Dim myScriptResult as String
myScriptResult = AppleScriptTask ("MyAppleScriptFile.scpt", "myapplescripthandler", "my, parameter, string")

And then create an AppleScript with Script Editor and save it in ~/Library/Application Scripts/com.microsoft.outlook/ folder, with the above name MyAppleScriptFile.scpt.

Because I've never had Outlook installed on any Mac, I don't have access to Outlook's AppleScript Dictionary, so I can't help you with specific Outlook Scripting, but the base of the AppleScript code using the above VBA code would be something like this.

Code:
-- AppleScript Code
on myapplescripthandler(param1, param2, param3)
    -- Do stuff with the handler params here
    tell application id "com.microsoft.outlook"
        -- You can also do stuff with handler params here as well
        -- Do stuff with the Outlook Application here
    end tell
    -- Because your VBA code module is expecting a String result, tell it what happened here
    return theResult as string
end myapplescripthandler

If you need any further help with AppleScript language specific things, I'll be happy to help.
But I can't test any Outlook application specific stuff, without access to the app or it's AppleScript dictionary.

I think you'll probably find loads of Outlook scripting resources online with a bit of searching.

Hope this helps

Regards Mark
 
Last edited:
I more than likely am misunderstanding it :confused::eek:...lol. I appreciate the insight. I will keep you posted with the results.

I appreciate the help Mark.



Although I haven't done any VB coding for about 15 years, or indeed used Microsoft products for as long as well.

I think your misunderstanding the difference between VBA and AppleScript.
Although your VBA code can be interpreted into AppleScript code, this would not help you.

VBA code is used as an application extension or plugin to the host application, and uses an OLE automation mechanism, and is driven by Application Events, as opposed to AppleScript's Apple Event mechanism.

Where as your VBA code module is almost part of the application's features, which could be run from the applications menu or toolbar, any AppleScript file would be an external script file, which would have to be double clicked or activated before it perform any actions.

But I believe if memory serves me correct, you can create a VBA code module from within the Outlook application with this sort of code here.

Code:
#VB Code
Dim myScriptResult as String
myScriptResult = AppleScriptTask ("MyAppleScriptFile.scpt", "myapplescripthandler", "my, parameter, string")

And then create an AppleScript with Script Editor and save it in ~/Library/Application Scripts/com.microsoft.outlook/ folder.

Because I've never had Outlook installed on any Mac, I don't have access to Outlook's AppleScript Dictionary, so I can't help you with specific Outlook Scripting, but the base of the AppleScript code using the above VBA code would be something like this.

Code:
-- AppleScript Code
on myapplescripthandler(param1, param2, param3)

end myapplescripthandler
[doublepost=1495223679][/doublepost]Although I haven't done any VB coding for about 15 years, or indeed used any Microsoft products in as long as well.

I think your misunder
 
At this point I'm questioning your reasons for wanting to use AppleScript for Microsoft Office automation.
Microsoft introduced Visual Basic for Applications a long time ago, with the main purpose of using it for automation of tssks within Office applications.
Clearly you know how to access the developer tools within the Outlook app, and you seem to be comfortable with the Visual Basic programming language.
So I feel compelled to ask the obvious question, why don't you use the built in automation tools?

The VB code modules work within the application's sandbox, and can use the application's native data types, while also being accessible from the application's menu's and toolbar's.
Surley that's preferable to an external automation script, written in a language your not familiar with.
Don't get me wrong, I'm sure you have good reasons, but I'm struggling to work them out myself.

Ironically the Apple industry experts, of which I am NOT one, have been rumouring over the last couple of years about AppleScript possably being deprecated, in favour of application extensions written in something like JavaScript.
I'm not sure how much we can trust these rumours, but this type of app extension could well end up being something similar to Microsoft's VBA system.
Ultimately only Apple insiders no the future of scripting and automation on Apple's platforms.

Regards Mark
 
Ironically the Apple industry experts, of which I am NOT one, have been rumouring over the last couple of years about AppleScript possably being deprecated, in favour of application extensions written in something like JavaScript.
I'm not sure how much we can trust these rumours

Yeah, I've been hearing that one for over ten years now! I think the problem is that they'd have to replace it with something as good or better (which I'd be over the moon about!).
 
superscape said:
Yeah, I've been hearing that one for over ten years now! I think the problem is that they'd have to replace it with something as good or better (which I'd be over the moon about!).

Yeah I think we've had this conversation before.

Like you I've also heard it a lot over the years, and will only beleive it when it happens.
But the warning signs are definatley there this time, with the tighter sanboxing rules, the JavaScript tab in the Xcode Documentation window, and the Cocoa Frameworks rapid shift towards Swift.
And also the departure of Sal Soghoian recently from Apple's employ, suggest changes in Apple's automation technologies may be closer than ever.

But as we've also both said before, it's a case of wait and see.

Mark
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.