[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Auto Add Contact Name into Subject Line of New Appointment in Calendar

Posted on 2006-07-06
20
Medium Priority
?
395 Views
Last Modified: 2010-05-19
When I am viewing a contact I can choose "New Appointment With Contact." It then takes me to a new calendar item screen and asks me to fill in the subject, location, etc... It puts the contact name at the bottom in the contact field, but I would also like it to automatically put the name of the contact in the subject line. Is there a way to do this? Thanks.
0
Comment
Question by:ohioequities
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 9
20 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 17054021
Hi ohioequities,

Not in the way you describe.  Using a bit of VBA scripting we could create a workaround, but you wouldn't be able to right-click and select "New Appointment With Contact".  You'd have to click a toolbar button instead.

Cheers!
0
 

Author Comment

by:ohioequities
ID: 17054381
Okay, that's fine, that's actually perfect. Could you show me how to write such a script, i have little to no experience doing such a thing, but I have no problem following close detailed instructions. Thanks.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17055786
Cool.  I'll get the code and instructions posted as quick as I can, but within the next 24 hours for sure.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 76

Expert Comment

by:David Lee
ID: 17062618
Here's the code for doing this.  Follow these instructions to set this up.

1.  Open Outlook.
2.  Click Tools->Macro->Visual Basic Editor
3.  If it's not already expanded, then expand Microsoft Outlook Objects.
4.  Once expanded you should see ThisOutlookSession.  Click on it.
5.  Copy the code from the <THISOUTLOOKSESSION CODE> section and paste it into the right-hand code window.
6.  If it's not already expanded, expand Modules and click on Module1.
7.  Copy the code from the <MODULE1 CODE> section and paste it into the right-hand code window.
8.  Exit the editor.  It'll save everything automatically.
9.  Click Tools->Macro->Security.
10. Set the security level to Medium.
11. Close Outlook.
12. Launch Outlook.
13. When Outlook starts you'll receive a pop up dialog-box warning that ThisOutlookSession contains macros and asking if you want to enable them.  You have to say yes and enable them for the code to work.

The first think you should notice is a new icon on your toolbar (2nd icon from the left).  If you click that button while a contact is selected, then Outlook will create a new meeting request addressed to that person.  It will also put the contact's name in the subject line and will create a link back to the contact.  If you click that button when a contact is not selected, then nothing will happen.

'<THISOUTLOOKSESSION CODE>
Dim WithEvents olkControl As CommandBarButton

Private Sub Application_Quit()
    Set olkControl = Nothing
End Sub

Private Sub Application_Startup()
    Dim olkExp As Outlook.Explorer, _
        olkBar As Office.CommandBar
   Set olkExp = Outlook.ActiveExplorer
   Set olkBar = olkExp.CommandBars.Item("Standard")
   'Test to see if the toolbar button already exists
   Set olkControl = olkBar.FindControl(, , "ApptWithContact")
   'If not found, then create button
   If olkControl Is Nothing Then
      Set olkControl = olkBar.Controls.Add(, , , 2, True)
      With olkControl
         .Caption = "Make Appointment"
         'Find the button face id's here: http://www.outlookexchange.com/articles/toddwalker/BuiltInOLKIcons.asp
         .FaceId = 1097
         .Style = msoButtonIconAndCaption
         .Tag = "ApptWithContact"
         .Visible = True
      End With
   End If
End Sub

Private Sub olkControl_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
    NewAppointmentWithContact
End Sub
'</THISOUTLOOKSESSION CODE>


'<MODULE1 CODE>
Sub NewAppointmentWithContact()
    Dim olkAppointment As Outlook.AppointmentItem, _
        olkContact As Outlook.ContactItem
    If Application.ActiveExplorer.Selection(1).Class = olContact Then
        Set olkContact = Application.ActiveExplorer.Selection(1)
        Set olkAppointment = Application.CreateItem(olAppointmentItem)
        With olkAppointment
            .Links.Add olkContact
            .Recipients.Add olkContact.LastNameAndFirstName
            .Subject = olkContact.FullName
            .Display
        End With
        Set olkContact = Nothing
        Set olkAppointment = Nothing
    End If
End Sub
'</MODULE1 CODE>
0
 

Author Comment

by:ohioequities
ID: 17070080
Thank you. That was a great help. I followed all of your instructions and that worked great. The only question I have is if it's possible to take the line of code out that automatically puts it at the 2nd icon to the left. I have experience right clicking on the toolbar, clicking customize and then selecting the macro from the list. This is what I had to do in order to get that button to show on the toolbar when in the Contacts menu. So that's my first question. My second question is this. I have one more macro that I need to write. Or at least I need to write a macro to do this. I have a bunch of word documents that are templates that I use on a day to day basis in order to send letters to clients. I would like to be able to add a context menu inside of outlook that when I am on a contact, I can click open an existing word document, and have all of that person's contact information automatically be added to that word document in a certain place. Essientially, I am describing a mail merge, but in this case I am only talking about adding that one contact to the word document. I know there are ways to do this from word, but it takes a long time to go through the wizard. You seem to know your way around outlook pretty well, is there a way to accomplish what I am describing. And keep in mind that I have numerous templates I would like to apply this to. Thanks again for all your help, I will make sure to award you the most points I can.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 17071557
> it's possible to take the line of code out that automatically puts it at the 2nd icon to the left
No problem.  This line of code controls where the toolbar button is placed.

    Set olkControl = olkBar.Controls.Add(, , , 2, True)

Change 2 to whatever number you desire.  It represents the control the button will go before.  So a 2 should place it before the current second button making it the second button.

> I have one more macro that I need to write.
This is definitely doable, but I'm not sure I'm the right person for this.  The code for doing this is going to involve Word much more than Outlook.  I'm not nearly as knowledgeable with Word macros.  I also have to check my Outlook documentation, but I'm not sure about adding context menus.  In all fairness this really needs to be a separate question.  If you want to open a second question, then I'll take a look at doing this or collaborating with a Word macro expert to help pull it together for you.
0
 

Author Comment

by:ohioequities
ID: 17071866
Okay, thanks. I will definitely go ahead and open a seperate question right now. Thanks for all your help.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17072256
You're welcome.  Happy I could help out.  I see the other question.  I'll get to it as quick as I can.
0
 

Author Comment

by:ohioequities
ID: 17072334
I'm sorry, there is a little bit of an error, in the script above. It works okay on my computer, but not on my business partners computer. The first problem is that I can't put a ' in front of the line Set olkControl = olkBar.Controls.Add(, , , 2, True), if i do, it keeps giving me debug errors when i open up outlook. perhaps we could rewrite that top script so that it doesn't automatically put the button anywhere on startup, i'm perfectly fine with customizing the toolbars through outlook instead of through the vb. however, there is one other problem that i didn't anticipate. Sometimes rather than browsing for a contact, we just type a contacts name into the search window and then click on the contacts name. when we are on that screen, if we click make appointment it will not work because it doesn't know that we have a contact selected. is there any way to fix this?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17077449
> I can't put a ' in front of the line Set olkControl = olkBar.Controls.Add(, , , 2, True)
Why would you want to? The rest of the code in that procedure depends on that control being set.  If you want to create the button manually, then remove the top block of code altogether.  The button you create will need to call the script in the second block.

> we just type a contacts name into the search window and then click on the contacts name
Meaning that you open the contact, or that you highlight the name in the search results window?


0
 

Author Comment

by:ohioequities
ID: 17077656
First comment: I think its cool how you can automatically program the code to put the button on the toolbar on startup, but everyone I will be doing this for may want the button in a different place, and sometimes they want it on the top toolbar, so it may just be easier for me to creat the button manually. So basically what you are saying is to do away with the <ThisOutlookSession> Code and just keep the Module 1 Code?

Second Comment: Correct, meaning that I open the contact by double clicking on it in the search results window.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17077908
Thanks.  I posted the code for adding the button automatically just to make things easy.  It's certainly not necessary.  If you don't need it, then leave out all the code in <ThisOutlookSession>

If the contact is open, then the following code should get the job done.  Substitute the code below for the Module1 code you already have.  I made these changes off the top of my head without testing, so there may be errors.  I'll test it as soon as I can.

Sub NewAppointmentWithContact()
    Dim olkAppointment As Outlook.AppointmentItem, _
        olkContact As Outlook.ContactItem
    If Application.ActiveExplorer.Selection(1).Class = olContact Then
        Set olkContact = Application.ActiveExplorer.Selection(1)
    Else
        If Application.ActiveInspector.CurrentItem.Class = olContact Then
            Set olkContact = Application.ActiveInspector.CurrentItem
        Else
            Set olkContact = Nothing
        End If
    End If
    If TypeName(olkContact) = "ContactItem" Then
        Set olkAppointment = Application.CreateItem(olAppointmentItem)
        With olkAppointment
            .Links.Add olkContact
            .Recipients.Add olkContact.LastNameAndFirstName
            .Subject = olkContact.FullName
            .Display
        End With
        Set olkContact = Nothing
        Set olkAppointment = Nothing
    End If
End Sub
0
 

Author Comment

by:ohioequities
ID: 17078217
It appears as if there is something wrong with this line, outlook takes me to this line for debugging >> Set olkAppointment = Application.CreateItem(olAppointmentItem) <<
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17078285
How are you running the code?  I just ran through it several times in a row and never had an error.
0
 

Author Comment

by:ohioequities
ID: 17078385
All I'm doing is adding it to the toolbar, searching for a contact, and then clicking the button, and then it tells me Runtime error 287.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17078427
Give me the exact steps you are following after the search is complete.
0
 

Author Comment

by:ohioequities
ID: 17078588
After the search is complete, I double click on the contact I want to open and it brings up the contact window. Then I click on the button called make new appointment.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17079859
Is it perchance a custom contact form instead of the default contact form?  What you described is exactly what I did and didn't encounter any problem.
0
 

Author Comment

by:ohioequities
ID: 17080555
Okay, I finally got it to work. I don't know what I did, or what I was doing wrong, but I ended up deleting everything, starting from stratch, and now it is working fine. I took out the startup script and just added the button on my own. Thank you for all of your help. Let me know how the other script is coming along.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17086335
Great.  I will.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question