Add-In button fails after document changes

D

DuvallBrian

I'm using office 2003 and have a Word Add-in built using the VBA editor the
comes with Office Pro.

The Add-In creates a command bar and adds a button with events. The onclick
event works for the first document. When you click the button on a second
document, the onclick event doesn't fire.

It will continue to work, if you only have one document open, meaning you
need to close one document and then open another for the onclick event to
fire and the code to execute.

Can anyone help as I don't understand why the event isn't firing for the
second documents.

Thanks,
Brian
 
D

Doug Robbins - Word MVP

The problem may be something to do with the code that is being executed by
the button. What is it?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

DuvallBrian

The intent of the add-in is to provide a quick way for me to create a follow
up task in Outlook with the path to the file as an attachment to the File.
Here's the basic code in the add-in.
When a connection with the add-in is created it recreates the commandbar and
the button.


Public WithEvents cbbDocumentTask As Office.CommandBarButton

Private Sub CreateBar()
Set cbNewBar = MyWord.CommandBars.Item("Outlook Bar")
If VBA.VarType(cbNewBar) <> vbNull Then cbNewBar.Delete

On Error Resume Next
MyWord.CommandBars.Item("Outlook Bar").Delete
Set cbNewBar = MyWord.CommandBars.Add("Outlook Bar",
Office.MsoBarPosition.msoBarTop)
With cbNewBar
Set cbbDocumentTask = .Controls.Add(Type:=msoControlButton,
Parameter:="Brians")
With cbbDocumentTask
.Caption = "New Task"
.TooltipText = "Create an Outlook task for the current
spreadsheet."
.BeginGroup = True
.Style = msoButtonCaption
End With
.Visible = True
End With
End Sub


Private Sub cbbDocumentTask_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
Debug.Print "Click"
Exit Sub
If bOutlookActive = True Then
Dim objNewTask As Outlook.TaskItem

If MyWord.ActiveDocument.Path = "" Then
MyWord.Dialogs.Item(wdDialogFileSaveAs).Display
If MyWord.ActiveDocument.Path = "" Then Exit Sub
End If

Set objNewTask =
MyOutlook.Session.GetDefaultFolder(olFolderTasks).Items.Add()
With objNewTask
.Subject = "Update " & MyWord.ActiveDocument.Name
.ReminderTime = DateAdd("d", 1, VBA.Now())
.ReminderSet = True
.Attachments.Add MyWord.ActiveDocument.FullName,
Outlook.OlAttachmentType.olByReference, , MyWord.ActiveDocument.Name
.Save
.Display
End With

End If
End Sub
 

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