Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2006

Tip: Looking for answers? Try searching our database.

Add-In button fails after document changes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DuvallBrian - 27 May 2006 07:09 GMT
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
Doug Robbins - Word MVP - 27 May 2006 07:34 GMT
The problem may be something to do with the code that is being executed by
the button.  What is it?

Signature

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

> I'm using office 2003 and have a Word Add-in built using the VBA editor
> the
[quoted text clipped - 14 lines]
> Thanks,
> Brian
DuvallBrian - 28 May 2006 07:43 GMT
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

> The problem may be something to do with the code that is being executed by
> the button.  What is it?
[quoted text clipped - 17 lines]
> > Thanks,
> > Brian
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.