#1
|
|||
|
|||
Userform button: the object invoked has disconnected from its clients
We recently upgraded our version of Office (subscription plan) and now our user form buttons that call a sub routine, no longer work.
Here is a sample of the code. When the Beta sub is called, the error is displayed and you have to kill the Word session using Task Manager to exit. We have a similar issue with Excel so it seems to be an Office issue. Code:
Private Sub cmdCancel_Click() End End Sub Private Sub cmdYes_Click() If OptionButton1 Then Call Beta If OptionButton2 Then Call Internal End Sub Sub Beta() Unload frmBetaInternal With Selection .HomeKey Unit:=wdStory .Find.ClearFormatting .Find.Replacement.ClearFormatting End With With Selection.Find .Text = "Contents" .Forward = True .Wrap = wdFindContinue End With Selection.Find.Execute Selection.MoveLeft Unit:=wdCharacter, Count:=3 Application.Templates(ActiveDocument.AttachedTemplate.FullName). _ BuildingBlockEntries("Disclaimer").Insert Where:=Selection.Range, RichText:=True Selection.HomeKey Unit:=wdStory 'Insert draft watermark Dim oSection As Section Dim oHeader As HeaderFooter Dim oRng As Range For Each oSection In ActiveDocument.Sections For Each oHeader In oSection.Headers Set oRng = oHeader.Range oRng.Collapse wdCollapseEnd Application.Templates(ActiveDocument.AttachedTemplate.FullName). _ BuildingBlockEntries("DraftWatermark").Insert Where:=oRng, _ RichText:=True Next oHeader Next oSection End Sub |
#2
|
||||
|
||||
Which line is the error occurring on? That will make it easier to diagnose.
My observations are: 1. It is unusual to unload the userform and then expect the rest of the code to proceed since that code is inside the userform. I would recommend you remove that line from the Beta macro and put it at the end of the cmdYes_Click macro. Or better still, put it in the macro that called the userform in the first place. I use Me.Hide at the end of macros when I want to get rid of the userform. This allows the code to run to completion. 2. Application.Templates(ActiveDocument.AttachedTempl ate.FullName). is overly indirect. Try this instead ActiveDocument.AttachedTemplate.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Resolution, somewhat...
So it turns out that we had a Beta channel Office 365 version that was causing the issue. It does not have any to do with the VBA code! Apparently, there is a registry entry that gets corrupted and by rolling back to a GA version (2106), the issue goes away.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Automation Error - the object invoked has disconnected from its clients | mktate | Word VBA | 2 | 03-20-2019 06:06 PM |
Executing a userform with a command button | spc94 | Word VBA | 2 | 06-24-2015 10:08 PM |
VBA Code in a UserForm module to delete a Command Button which opens the userform | Simoninparis | Word VBA | 2 | 09-21-2014 03:50 AM |
Command button to show userform suddenly stopped working | jpb103 | Word VBA | 0 | 05-22-2014 06:05 AM |
Word doc bug when closing from userform command button click macro | Joe Patrick | Word | 1 | 07-05-2011 08:53 PM |