Is it possible to modify the behavior of existing buttons in outlook (or generally in ms office programs)? E.g. can I make the "send mail" button show a dialog before sending a mail?
I know that you can make add ins and put them into ribbon but can you add certain behavior to existing controls?
Use Microsoft.Office.Interop.Outlook und handle the Send event. You can find the documentation here.
You have use your application reference to get the active inspector and by the active inspector you retrieve the message class:
(CType(inspector.CurrentItem, Outlook.ItemEvents_10_Event)).Send += New Outlook.ItemEvents_10_SendEventHandler(Inspector_Send)
Private Sub Inspector_Send(ByRef Cancel As Boolean)
... your code...
End Sub
Related
Basically I am using below code to run macro after I manually open a specific email.
The code and macro works ,but I noticed there is a slowness while opening of any email on outlook.
After many tests, I find out this line is the cause of issue:
Set MyItem = Item
And this the full code:
Option Explicit
Option Compare Text
Public WithEvents MyItem As Outlook.MailItem
Private Sub Application_ItemLoad(ByVal Item As Object)
If Item.Class = olMail Then
Set MyItem = Item 'This line cause slow opening of any email
End If
End Sub
Private Sub myItem_Open(Cancel As Boolean)
If MyItem.Subject = "Test Email" Then
'Code
End If
End Sub
Kindly How to fix this issue?
Basically I am using below code to run macro after I manually open a specific email.
You may consider using other event handlers in Outlook - for selecting in the Explorer window you may try to handle the SelectionChange event of the Explorer class which is fired when the user selects a different or additional Microsoft Outlook item programmatically or by interacting with the user interface. For opening in the separate window you can handle the NewInspector event which is fired whenever a new inspector window is opened, either as a result of user action or through program code. The event occurs after the new Inspector object is created but before the inspector window appears. Also you may handle the Inspector.Activate event which is fired when an inspector becomes the active window, either as a result of user action or through program code.
If there is a specific reason to use the ItemLoad event handler in the code you may continue using the late-binding technology and keep the item defined as object.
Also don't forget to release corresponding objects in the Unload event of the Item-level events.
I'm trying to write an extension to my Outlook calendar - More specifically the appointment module. (Form designer)
I have a button in my designer, that I want to write some simple code around.
Sub CommandButton1_Click()
msgbox "Hello World"
End Sub
The above code is put into the code editor that appears when I press "View code". Nothing happens.
How do I get a commandbutton to trigger a simple alert in the Outlook form designer?
Custom form script is now disabled by default. You can see more details for the known issue and you can re-enable it as the following link suggests.
You can read more about that in the Custom Form Security Changes article
I implement context menus for emails, this includes the explorer reading pane. To get the text under the mouse at the time of a right click I use the WordEditor. I do not think there is any other way of finding out where the mouse has clicked.
'_olItem comes from the current selection
olInspector = CType(_olItem.GetInspector, Outlook.Inspector)
wDoc = CType(olInspector.WordEditor, Word.Document)
'then go off and work with word
For the Explorer reading pane is the only way to get the WordEditor by first calling GetInspector?
One reason for asking is that I see that for Inline responses Outlook has the ActiveInlineResponseWordEditor property.
My addin also listens for new inspectors
Private Sub oInsps_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles oInsps.NewInspector
'do something here with this inspector
End Sub
If I cannot avoid calling GetInspector to get the word editor then is there a property of the inspector at the time the newinspector event fires to tell me that this inspector is actually from the reading pane and from me calling GetInspector?
Use Explorer.PreviewPane.WordEditor.
I'm making an AppLock for Office and I want to lock features, like open, save and saveas with a password
Can I make something like this?
Public Sub ThisAddIn_OnSave(sender As Object, e As SaveEventArgs) Handles Me.OnSave
If <my_condition> Then
e.Cancel = True
End If
End Sub
It depends on the Office application you want to integrate with. For example, in Word you can handle the Application.DocumentBeforeSave event.
Otherwise, you can intercept Ribbon button commands and execute your custom code that way.
Repurposing ribbon controls is not enought for preventing users from doing such actions.
A keyboard shortcut can be used (for example, Ctrl+S for saving documents). You need to set a keyboard hook for repurposing keyboard shortcuts, see Using shortcut keys to call a function in an Office Add-in for more information.
Is there a way to disable the message (and have the document editable by default):
Server Document To modify document, click Edit Document followed by the button with text "Edit Document".
I cannot find a word setting to do this. In addition I cannot see a way to make a VB macro to do this with a key stroke. I have used a small autohotkey script to position the mouse and click this prompt, but this does not always work since it depends on the position of the window. it is impossible to use the tab key to get to this prompt.
I have to modify about 50+ documents a day from sharepoint, ideally I would like to combine this with another macro which does other automated processing for me. But I can't find a VB solution for clicking the Edit button.
Depending on your security settings (you mentioned that they were blocked), this may or may not work.
Create a new macro enabled template in your Word startup folder (usually at C:\Users[YourID]\AppData\Roaming\Microsoft\Word\STARTUP), and add a new class module. I called mine "AutoEditEnable". You can name it anything, but you'll need it to match how you declare it in the other module.
This code goes in the class:
Option Explicit
Private WithEvents app As Application
Private Sub Class_Initialize()
Set app = Application
End Sub
Private Sub app_ProtectedViewWindowOpen(ByVal PvWindow As ProtectedViewWindow)
PvWindow.Edit
End Sub
Basically, this will hook any Application events you need to - in this case the ProtectedViewWindowOpen event or the ProtectedViewWindowActivate event (either should work).
Put the following code in ThisDocument to grab a reference to it when your template loads:
Option Explicit
Private hook As AutoEditEnable
Private Sub Document_Open()
Set hook = New AutoEditEnable
End Sub
Close Word and restart it, then make sure your new template shows up as a loaded add-in.