How to Open Outlook Templates and Files using Toolbar Buttons

Chia sẻ bởi:hands
★★★★★
Quảng cáo

When you want to open a template, you need to go through the Choose Form dialog, which is a few more steps than most users want to take. In older versions of Outlook you could create Hyperlink buttons but Outlook 2010 and newer doesn't support hyperlink buttons and tighter security in Outlook now means you need to respond to a warning dialog before the template (or hyperlinked file) opens.

You have some options to make using templates easier: Pin the template to Outlook's taskbar icon, Copy it into a folder in your data file, drag it to your desktop, or use a macro to open it.

If the template does not contain controls that require you to open it from the Template folder, you can store the template in other locations, including the Documents folder or Desktop; pin it to the Outlook icon on the taskbar, or copy it into a folder in your Outlook data file.

Pinned Templates

All email templates and some calendar and contacts templates can be opened using these methods. Templates containing scripts or some controls must be opened using the Template dialog.

Email templates that are pinned to the Outlook button on the taskbar are accessed by right-clicking on the Outlook button or you can copy the template to a folder in your Outlook data file. Recently used templates that are not already pinned may be listed on the Outlook icon's right-click menu.

cdn.slipstick.com/images/2011/outlook/pinned.gif

To pin a template, drag it from the template folder at C:Users%username%AppDataRoamingMicrosoftTemplates and drop on the taskbar button. To copy it to an Outlook folder, drag it to the desired folder. (I use a folder named Templates).
cdn.slipstick.com/images/2011/outlook/drag-to-pin.gif

[URL='www.slipstick.com/outlook/hyperlink-templates/#toolbar']

Open templates using a toolbar button

If you prefer to use a button on Outlook's toolbar, you can use a macro to open the template. To disable the warning message, you need to set a registry key.

See [URL='www.slipstick.com/how-to-outlook/disable-unsafe-hyperlink-warning-opening-attachments/']Disable the Unsafe Hyperlink Warning when Opening Attachments for the instructions to disable the warning dialog and the Open or Save dialog. Use this registry value with Outlook 2010 and newer if you add files to Outlook's Shortcut navigation pane.

To create a button on the toolbar that will open a template in Outlook 2010 and up, you need to use a macro as it does not support hyperlink buttons found in older versions of Outlook. Additionally, opening a template hyperlinked to a toolbar button in Outlook 2007 brings up a security dialog.

cdn.slipstick.com/images/2011/08/template-warnings-280×223.png

Note: if the template contains custom fields, the customizations will be disabled and the template will be blank. These templates need to be opened using the Choose Form dialog.

The solution

Create a macro that replicates opening a template from the Choose Form dialog using the Application.CreateItemFromTemplate method:

Sub MakeItem()
Set newItem = Application.CreateItemFromTemplate("c:pathtemplate.oft")
newItem.Display
Set newItem = Nothing
End Sub

Press Alt+F11 to open Outlook's VB Editor then copy and paste this macro into ThisOutlookSession. Add it to the ribbon or QAT. See [URL='www.slipstick.com/developer/how-to-use-outlooks-vba-editor/']How to use the VBA Editor for complete instructions to use the VB Editor. See [URL='www.slipstick.com/outlook/customize-toolbar-ribbon-or-qat/']Customize the QAT if you need help customizing the QAT.

If you want to use a macro to open different templates, assign the template path to a variable and pass the variable to the macro, like this:

Dim template As String

Sub OpenTemplate1()
template = "C:UsersDianeTemplatestemplate1.oft"
MakeItem
End Sub

Sub OpenTemplate2()
template = "C:UsersDianeTemplatesemail.oft"
MakeItem
End Sub

Private Sub MakeItem()
Set newItem = Application.CreateItemFromTemplate(template)
newItem.Display
Set newItem = Nothing
End Sub

Send message to Contact using a template

This version of the macro will use a template to send a message to the selected contact.

This macro works with the selected contact. You can use it if a contact is open, as long as the contact is also the selected item. If you open a contact, read an email then switch to the already-open contact, you will need to use the GetCurrentItem function on this page: [URL='www.slipstick.com/developer/outlook-vba-work-with-open-item-or-select-item/']Outlook VBA: Work with Open Item or Selected Item

Sub SendToContact()
Dim strAddress As String
Dim objItem

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

If objItem.Class = olContact Then
     strAddress= objItem.Email1Address & ";"
 End If

Dim newItem as Outlook.MailItem
Set newItem = Application.CreateItem("C:pathtemplate.oft")
newItem.To = strAddress
newItem.Display
End Sub

Open a Template and Add an Attachment

If you want to add an attachment to the message at the same time you open the template, you'll use newItem.Attachments.Add "C:myfile.doc". Add it to your code after the line that opens the template (DUH!) and before the message is displayed (newItem.Display).

The macro will look something like this:

Sub AddAttachment ()
Dim newItem as Outlook.MailItem
Set newItem = Application.CreateItem("C:pathtemplate.oft")
newItem.Attachments.Add "C:myfile.doc"
newItem.Display
End Sub

Open a published form

If you want to open a published form, use this code to call the form. You need to be viewing the folder you want the item to be saved in.

Use GetDefaultFolder function to use the default folder for the custom form type. For example, change the Set items line to this the following to create an appointment or meeting in the Calendar folder from any other folder:
Set Items = Session.GetDefaultFolder(olFolderCalendar).Items

Public Sub OpenPublishedForm()
   Dim Items As Outlook.Items
   Dim Item As Object
   Set Items = Application.ActiveExplorer.CurrentFolder.Items
   Set Item = Items.Add("ipm.note.name")
   Item.Display
 End Sub

Open a web page

Use this script if you want to open a web page using a button on Outlook's ribbon.

Sub OpenWebpage()
CreateObject("WScript.Shell").Run ("www.slipstick.com/")
End Sub

More fun with hyperlinks:
[URL='www.slipstick.com/developer/custom-form/create-hyperlink-outlook-form/']Create a Hyperlink on an Outlook Custom Form
[URL='www.slipstick.com/developer/code-samples/open-hyperlinks-email-message/']Open All Hyperlinks in an Outlook Email Message

[URL='www.slipstick.com/outlook/hyperlink-templates/#button']

Add a button to the ribbon tutorial

This tutorial shows you how to add a button to one of Outlook 2013's ribbon tabs. If you prefer to add them to the Quick Access Toolbar (QAT), the steps are the same but you'll start in File, Options, Quick Access Toolbar. Note: In Outlook 2010 you cannot add buttons to the ribbon but you can add buttons to the QAT.

  • Select Macros from the Choose commands from menu
  • Select the macro. Only Public macros that you can run manually will be listed here.
  • Click Add to add it to the QAT (or ribbon)
  • To change the icon and display name, click Modify.

After you add a macro the ribbon, you cannot move the macro or change the macro or module name. If you do, you'll need to recreate the macro.

[URL='cdn.slipstick.com/images/2011/outlook/add-macro-to-qat.png']cdn.slipstick.com/images/2011/outlook/add-macro-to-qat-575×390.png

NeF9f4Xi97I

[URL='www.slipstick.com/outlook/hyperlink-templates/#fileopen']

Select a template from File Open dialog

The macro will open the File Explorer dialog to a specific folder for you to choose a template. This macro uses late binding, so you won't need to set a reference to the Word object model to use it.

Sub ShowOpenDialog()
'Display the Open dialog box
Dim wdApp As Object ' Word.Application
Dim dlgOpen As Object ' FileDialog
Dim strFile As String

'Set wdApp = New Word.Application
Set wdApp = CreateObject("Word.Application")
 Dim vrtSelectedItem As Variant
    'Set the dialog box type to Open
    Set dlgOpen = wdApp.FileDialog(msoFileDialogFilePicker)

'Show only Outlook templates in the specific folder path
    With dlgOpen
         .InitialFileName = "D:DocumentsSlipstick Templates"
        .Filters.Add "Outlook Template", "*.oft"

If .Show = -1 Then
      strFile = .SelectedItems(1)

Set newItem = Application.CreateItemFromTemplate(strFile)
      newItem.Display
    Else
    ' user clicked cancel
    End If

End With

End Sub

This works in Outlook 2007 and older versions as well as all Office applications that have the Assign Hyperlink option on customized buttons. You can hyperlink to any file, although programs (*.exe) may be restricted for security reasons.

cdn.slipstick.com/images/2011/08/assign-hyperlink-575×292.png

You can use any button in the Customize dialog (select a category on the left to see additional buttons). If you want to create a menu button, there is a blank one in the New Menu category.

  • Right click on the toolbar area.
  • Choose Customize
  • From the Commands tab, drag a button (any button) to the Menu bar or a Toolbar
  • Right click on the button to expand the customize menu
  • Click Assign Hyperlink then Open and select the file you want to open.

Video Tutorial

In Outlook 2007's main interface and in Outlook 2003 and older, you'll add a button to the toolbar as shown in the following video.

videos.files.wordpress.com/Envs3ce2/customize-toolbar_dvd.mp4
[URL='www.slipstick.com/outlook/hyperlink-templates/#disable']

When you open templates or files using a hyperlink button or from Outlook's Shortcut navigation pane, you'll receive an unsafe hyperlink warning. You can disable the warning by editing the registry.

cdn.slipstick.com/images/2011/08/unsafe-warning.png

You may also receive the file open or save dialog when using a hyperlink button or shortcut. To disable this dialog when the "Always ask" field is grayed out, run Outlook as administrator. The "always ask" checkbox should be clickable. If not, you'll need to edit the registry for each file type. See [URL='www.slipstick.com/problems/disable-always-ask-before-opening-dialog/']Disable "Always ask before opening" dialog for more information.

cdn.slipstick.com/images/2011/08/open-save-dialog-378×207.png

The solution

Add a registry value to disable the warning dialog.

Open the registry editor and browse to the following registry subkey for
Outlook 2016 / 2019 / 365:
HKEY_CURRENT_USERSoftwareMicrosoftOffice16.0CommonSecurity

Outlook 2013:
HKEY_CURRENT_USERSoftwareMicrosoftOffice15.0CommonSecurity

Outlook 2010:
HKEY_CURRENT_USERSoftwareMicrosoftOffice14.0CommonSecurity

Outlook 2007:
HKEY_CURRENT_USERSoftwareMicrosoftOffice12.0CommonSecurity

Note: If the Security key does not exist in your registry, you'll need to create it too.

Right click on Security key and choose New, DWORD. Type (or paste)

DisableHyperlinkWarning as the Value name then double click on it. Enter 1 as the Value data to disable the warning. Delete the key or use a value of 0 to enable the warning.

cdn.slipstick.com/images/2011/08/value-data.png

Group policy keys for administrators

Administrators will add the DisableHyperlinkWarning DWORD to the Policy key instead:

Outlook 2016 / 2019 / 365:
HKEY_CURRENT_USERSoftwarePoliciesMicrosoftOffice16.0CommonSecurity

Outlook 2013:
HKEY_CURRENT_USERSoftwarePoliciesMicrosoftOffice15.0CommonSecurity

Outlook 2010:
HKEY_CURRENT_USERSoftwarePoliciesMicrosoftOffice14.0CommonSecurity

Outlook 2007:
HKEY_CURRENT_USERSoftwarePoliciesMicrosoftOffice12.0CommonSecurity

Do It For Me

If you don't want to edit the registry yourself, you can download and run the following registry key for your version of Outlook.

[URL='www.slipstick.com/reg/DisableHyperlinkWarning-2016.reg']Outlook 2016[URL='www.slipstick.com/reg/DisableHyperlinkWarning-2013.reg']Outlook 2013[URL='www.slipstick.com/reg/DisableHyperlinkWarning-2010.reg']Outlook 2010
[URL='www.slipstick.com/reg/DisableHyperlinkWarning-2007.reg']Outlook 2007

How to use the macros on this page

First: You need to have macro security set to the lowest setting, Enable all macros during testing. The macros will not work using the options that disable all macros or unsigned macros. You could choose the option to warn about macros and accept it each time you restart Outlook, however, because it's somewhat hard to sneak macros into Outlook (unlike in Word and Excel), allowing all macros is safe, especially during the testing phase. You can sign the macro when it is finished and change the security to allow signed macros.

To check your macro security in Outlook 2010 and newer, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, look at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or [URL='www.slipstick.com/developer/how-to-use-outlooks-vba-editor/#selfcert']sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  • Right click on Project1 and choose Insert > Module
  • Copy and paste the macro into the new module.

More information as well as screenshots are at [URL='www.slipstick.com/developer/how-to-use-outlooks-vba-editor/']How to use the VBA Editor

More Information
[URL='https://www.vboffice.net/en/developers/open-custom-form-via-your-own-ribbon']Outlook 2010: Open custom form via your own ribbon (vboffice.net)
[URL='www.slipstick.com/whitepapers/white%20paper%20-%20opening%20a%20saved%20outlook%20template.pdf']Opening a Saved Outlook Template (.oft file) in Office 2003 and 2007 Whitepaper by Helen Feddema
[URL='docs.microsoft.com/en-US/office365/troubleshoot/administration/enable-disable-hyperlink-warning']How to enable or to disable hyperlink warning messages in 2007 Office programs and in Office 2010 programs (MSKB)

www.slipstick.com/outlook/hyperlink-templates/#fileopen

Khóa học Power PI – Ứng dung trong Nhân sự
Khóa học SprinGO phù hợp

Khóa học Power PI – Ứng dung trong Nhân sự

TỔNG QUAN KHÓA HỌC: POWER BI CHO NGÀNH NHÂN SỰ Khóa học Power BI cho Nhân sự được thiết kế dành riêng cho các...

Xem khóa học
★★★★★ 5 ★ 1 👤 0 ▥ 0
Quảng cáo

Bạn nên đọc

Bình luận

Quảng cáo

Cũ vẫn chất

Xem thêm