really simple form question from a newbie

D

Dan Hardy

I am trying to create a toolbar button which will insert a timestamp
into my contact note field when I click it.

Here is the text of my attempt so far:

Sub timestamp()
Selection.Type Text:=Now
End Sub

However, I get a runtime 424 error. I have created this macro from
the contact>tools>forms menu and I didn't think I'd have to reference
the object, but I guess I do. Can someone help?

Thanks.
 
S

Sue Mosher [MVP]

Your message is unclear about whether you're putting code in an Outlook form (in which case the syntax is incorrect) or writing VBA code. Which is it?
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
D

Dan Hardy

It's in the form. Sorry.

Sue Mosher said:
Your message is unclear about whether you're putting code in an Outlook
form (in which case the syntax is incorrect) or writing VBA code. Which
is it?
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP]

Outlook has no Selection object and provides no way to get the insertion point in an Outlook item. Also, yoiu cannot create a toolbar button using Outlook form code. What you can created is a button on the form itself.

You might want to look at the macro at http://www.slipstick.com/dev/code/stampdate.htm, which shows how to append a date stamp to the existing contents of a contact item.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
S

Siegfried Weber

Sue Mosher said:
Outlook has no Selection object and provides no way to get the insertion
point in an Outlook item. Also, yoiu cannot create a toolbar button using
Outlook form code.

Actually, it is not only possible to add a toolbar button with VBScript from
within the item_open event of an Outlook form but it's also fairly simple.
Here's a code snippet:

Function Item_Open()
Set objInspector = Item.Application.ActiveInspector
Set objCommandbar = objInspector.CommandBars.Item("Standard")
Set objButton = objCommandbar.Controls.Add
With objButton
.ToolTipText = "Open Word"
.FaceID = 42
.Tag = "OpenWord"
.Caption = "Word"
.OnAction = "OpenWord"
.Style = msoButtonIconAndCaption
End With
End Function

Function OpenWord()
MsgBox("do your stuff here")
End Function

The above code adds a new button to the standard toolbar of an Outlook form
and sets the Word 2002/2003 icon. Once hitting the toobar button it displays
a message box.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top