Programmatically add a hyperlink button to outlook 2007 - vba

I am adding a toolbar to Outlook.
The toolbar will have one button on it.
This button, when pressed, will open up a web site.
I've created the button & toolbar no problem, but cannot work out how to add the hyperlink?
Set oTBar = oView.Add("toolbarname")
oTBar.Position = 1
oTBar.Visible = true
Set oButton = OTBar.Controls.Add
With oButton
.Caption = "Click here!"
.Style = 3
.HyperlinkType = 1
.FaceId = 1707
End with

Haha!
You need to add it as the tooltip:
.ToolTipText = "http://your_url"

Related

Use the Default Background Color Picker Popup menu

Summary:
I'm trying to make a custom popup menu with some options, amongst which i would like to insert the default background color picker from the Text Formatting tab. With this, i would love if i could know which color code has been picked so i can set it as a background color for a textbox.
What i have tried:
Sub Make_Popup_CuloriForm()
'Add PopUp menu
With Application.CommandBars.Add(Name:=Mname, Position:=msoBarPopup, _
MenuBar:=False, Temporary:=True)
With .Controls.Add(Type:=msoControlButton)
.Caption = "Actualizeaza formular"
.OnAction = "fCuloriForm"
.Parameter = "1"
.FaceId = 159
.BeginGroup = True
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "Elimina formular"
.OnAction = "fCuloriForm"
.Parameter = "2"
.FaceId = 330
.BeginGroup = True
End With
End With
' Application.CommandBars.Add c(36)
End Sub
What i need is to add another control to the popup menu, but that should be the builtin color picker.
thank you
LE:
This is what i need:

How can i use picture as icon in shortcut menu vba access?

I tried this
Set cbCat = CommandBars.Add(conBarName, msoBarPopup, False, False)
Set cbCatCtrl = cbCat.Controls.Add(msocontrolpopup)
cbCatCtrl.Caption = "Open Form"
Do While Not rsForms.EOF
Set cbObjectCtrl = cbCatCtrl.Controls.Add()
With cbObjectCtrl
.Caption = rsForms!Name
.Tag = rsForms!Name
.OnAction = "OpenForm"
' .Picture = stdole.StdFunctions.LoadPicture("D:\1.bmp")
But it doesn’t work , Error Invalid Picture , I tried .ICO Icons but still the same .
How can I load a picture from my pc and use it as icon instead of faceID method ?
Thanks in Advance
Hy,
I got this from :
Docs.Microsoft
It looks like you need to create a IPictureDisp first and then link this to the relevant control. Also try using a .bmp
Sub ChangeButtonImage()
Dim picPicture As IPictureDisp
Set picPicture = stdole.StdFunctions.LoadPicture( _
"c:\images\picture.bmp")
'Here you need to reference your control.
With Application.CommandBars.FindControl(msoControlButton)
'Change the button image.
.Picture = picPicture
End With
End Sub
Looking forward to your solution...

VBA to add a macro to the right mouse click in word

I'm running Word in Office 365; I have a Macro which I can run from a button added to the ribbon, but that requires access to the machine it's running on (at least, the way I did it) and this file is to go out to a distributed workforce.
I'm trying to write a macro in the document which will add a button to the drop-down menu that comes up when you right click on a text selection, but the code below doesn't add anything to the menu.
Sub AddToShortcut()
Dim Bar As CommandBar
Dim NewControl As CommandBarButton
DeleteFromShortcut
Set Bar = Application.CommandBars("Standard")
Set NewControl = Bar.Controls.Add(Type:=msoControlButton, ID:=1, Temporary:=True)
With NewControl
.Caption = "&New Action"
.OnAction = "AddAction"
.Style = msoButtonIconAndCaption
End With
End Sub
Private Sub document_open()
'adds the right-click shortcut when the document opens
Call AddToShortcut
End Sub
I got the core of the code from John Walkenbach's Excel VBA Programming for Dummies, so I'm presuming there's some difference between the way Word and Excel operate that's causing the issue?
You want to add it to the "Text" contextual menu, not "Standard."
The following is straight from Greg Maxey's page that you said was too much. It is the answer, though. Your code would be around oBtn.
You would put this in a Global Template stored in your Word Startup Folder (links to my pages). It could be renamed AutoExec or called from an AutoExec procedure in that template.
Option Explicit
Dim oPopUp As CommandBarPopup
Dim oCtr As CommandBarControl
Sub BuildControls()
Dim oBtn As CommandBarButton
'Make changes to the Add-In template
CustomizationContext = ThisDocument.AttachedTemplate
'Prevent double customization
Set oPopup = CommandBars.FindControl(Tag:="custPopup")
If Not oPopup Is Nothing Then GoTo Add_Individual
'Add PopUp menu control to the top of the "Text" short-cut menu
Set oPopUp = CommandBars("Text").Controls.Add(msoControlPopup, , , 1)
With oPopUp
.Caption = "My Very Own Menu"
.Tag = "custPopup"
.BeginGroup = True
End With
'Add controls to the PopUp menu
Set oBtn = oPopUp.Controls.Add(msoControlButton)
With oBtn
.Caption = "My Number 1 Macro"
.FaceId = 71
.Style = msoButtonIconAndCaption
'Identify the module and procedure to run
.OnAction = "MySCMacros.RunMyFavMacro"
End With
Set oBtn = Nothing
'Add a Builtin command using ID 1589 (Co&mments)
Set oBtn = oPopUp.Controls.Add(msoControlButton, 1589)
Set oBtn = Nothing
'Add the third button
Set oBtn = oPopUp.Controls.Add(msoControlButton)
With oBtn
.Caption = "AutoText Complete"
.FaceId = 940
.Style = msoButtonIconAndCaption
.OnAction = "MySCMacros.MyInsertAutoText"
End With
Set oBtn = Nothing
Add_Individual:
'Or add individual commands directly to menu
Set oBtn = CommandBars.FindControl(Tag:="custCmdBtn")
If Not oBtn Is Nothing Then Exit Sub
'Add control using built-in ID 758 (Boo&kmarks...)
Set oBtn = Application.CommandBars("Text").Controls.Add(msoControlButton, 758, , 2)
oBtn.Tag = "custCmdBtn"
If MsgBox("This action caused a change to your Add-In template." _
& vbCr + vbCr & "Recommend you save those changes now.", vbInformation + vbOKCancel, _
"Save Changes") = vbOK Then
ThisDocument.Save
End If
Set oPopUp = Nothing
Set oBtn = Nothing
lbl_Exit:
Exit Sub
End Sub

Set a CommandBar "Popup" submenu icon dynamically

I'm just trying to confirm this: In Office 2003, I want to create a custom submenu--what is known in CommandBar parlance as a popup (msoControlPopup)--at runtime, and set an image for it. With a CommandBarButton, this is very straightforward
Set btn1 = mnu.Controls.Add(msoControlButton, temporary:=True)
btn1.Caption = "Btn1"
btn1.Picture = stdole.LoadPicture("C:\temp\test.bmp")
But with a CommandBarPopup, or CommandBarControl of type msoControlPopup, it fails
Set sub1 = mnu.Controls.Add(msoControlPopup, temporary:=True)
sub1.Caption = "Sub1"
'object doesn't support this property or method for next line
sub1.Picture = stdole.LoadPicture("C:\temp\test.bmp")
The msoControlPopup type doesn't seem to allow a .Style property either, which is how Office determines what to show--icon, text, both--on the control. I haven't found this proven yet, so am holding out a last hope that I'm doing something wrong, and there is, in fact, a way to insert an icon on a submenu at runtime.
Thanks for any light you can shed.
Ok well more tumbleweeds. I'm pretty sure the answer to this is, it can't be done. And here's my "proof": None of the built-in submenus have icons (which I didn't realize until after I posted the above, and if you run the above code, go to Tools > Customize in the menu bar, then click on the Test menu to drop it down, and right-click on Sub1, you should see all the button and style options greyed out. Right-click on Btn1, and they're available.
Any other thoughts still welcome.
Of course if you need to set the image or FaceID of the submenu heading, that is not an available method for submenu headings, but if you want to set the image or FaceID on the submenu itself, I modified code from here to accomplish this:
Public Sub newSubMenu()
Dim menuBar As CommandBar
Dim newMenu As CommandBarControl
Dim menuItem As CommandBarControl
Dim subMenuItem As CommandBarControl
CommandBars("Sub Menu Bar").Delete
Set menuBar = CommandBars.Add(menuBar:=False, Position:=msoBarPopup, Name:="Sub Menu Bar", Temporary:=True)
Set newMenu = menuBar.Controls.Add(Type:=msoControlPopup)
newMenu.Caption = "&First Menu"
Set newMenu = menuBar.Controls.Add(Type:=msoControlPopup)
newMenu.Caption = "&Second Menu"
Set newMenu = menuBar.Controls.Add(Type:=msoControlPopup)
newMenu.Caption = "&Third Menu"
Set menuItem = newMenu.Controls.Add(Type:=msoControlButton)
With menuItem
.Caption = "F&irst Sub"
.FaceId = "356"
.OnAction = "myTest"
End With
Set menuItem = newMenu.Controls.Add(Type:=msoControlButton)
With menuItem
.Caption = "S&econd Sub"
.FaceId = "333"
.OnAction = "otherTest"
End With
Set menuItem = newMenu.Controls.Add(Type:=msoControlPopup)
menuItem.Caption = "Sub Menus"
Set subMenuItem = menuItem.Controls.Add(Type:=msoControlButton)
With subMenuItem
.Caption = "Item 1"
.FaceId = 321
.OnAction = "firstMacro"
End With
Set subMenuItem = menuItem.Controls.Add(Type:=msoControlButton)
With subMenuItem
.Caption = "Item 2"
'.FaceId = 432
.Picture = stdole.StdFunctions.LoadPicture("C:\temp\test.bmp")
.OnAction = "secondMacro"
End With
CommandBars("Sub Menu Bar").ShowPopup
End Sub
I tested this and it appears to work fine for both FaceID's and loaded pictures.
Of course to get the "on run time" affect, I would recommend placing this in a function which was called each time the user clicked on a specific control.
It could be further expended to handle variable pictures here as well.
Hope this helps.

How to add icons to custom menu in excel - vba

I have created some custom menu referring "Custom Menu visible to one document in Excel". Now I want to add some icons to each menu item. Either that may be system icons or some others. Please provide some solution.
use the .FaceID property. If you want to know what id to use, then download a FaceID Browser addin for excel. Example:
Set MenuItem = NewMenu.Controls.Add _
(Type:=msoControlButton)
With MenuItem
.Caption = "Save XML Data"
.FaceId = 270
.OnAction = "AskExportXml"
.Enabled = True
End With