[SOLVED] trouble fixing "object invoked has disconnected from its clients" error
Hello
First time writing a macro in word, here. I have a simple command button in my word doc which should bring up a userform which the user populates with information, etc. etc. Unfortunately, I'm getting the "object invoked has disconnected from its clients" error, which has a summary here: h t t p : / / support.microsoft.com/kb/319832
I've been googling this error for a couple hours now, and I guess I'm not understanding the suggested fixes, as they aren't working for me. Can anyone help me understand how to fix this? I thought that with the Dim/definition of my oWd variable I would be fixing the error, but the error persists.
I'll also note this weird thing: when I enter developer mode and double click on the button to call up the macro code, it comes up just fine. However, the very first time I hit F8, the word application automatically puts itself "on top" over the vba editor, but doesn't pop up the form. I have to manually click back into the vba editor, then hit F8 again, for the debugger to start actually stepping through the code.
The code is working just fine, the only problem is that once it's finished running, I can't edit, close, etc. the document because of the client disconnection error.
code for the command button:
code for the form:
Hello
First time writing a macro in word, here. I have a simple command button in my word doc which should bring up a userform which the user populates with information, etc. etc. Unfortunately, I'm getting the "object invoked has disconnected from its clients" error, which has a summary here: h t t p : / / support.microsoft.com/kb/319832
I've been googling this error for a couple hours now, and I guess I'm not understanding the suggested fixes, as they aren't working for me. Can anyone help me understand how to fix this? I thought that with the Dim/definition of my oWd variable I would be fixing the error, but the error persists.
I'll also note this weird thing: when I enter developer mode and double click on the button to call up the macro code, it comes up just fine. However, the very first time I hit F8, the word application automatically puts itself "on top" over the vba editor, but doesn't pop up the form. I have to manually click back into the vba editor, then hit F8 again, for the debugger to start actually stepping through the code.
The code is working just fine, the only problem is that once it's finished running, I can't edit, close, etc. the document because of the client disconnection error.
code for the command button:
Code:
Private Sub CommandButton1_Click()
UfNewSlice.Show
End Sub
code for the form:
Code:
Private Sub UfNewSlice_Initialize()
vbEntry.Value = "Enter product description here"
vbPubtag.Value = "Enter Pubtag here"
End Sub
Private Sub vbOK_Click()
On Error GoTo Err_Execute
Dim SliceEntry As String, PubTagEntry As String
SliceEntry = vbEntry.Value
If ActiveDocument.Bookmarks.Exists(PubTagEntry) = True Then
PubTagEntry = (vbPubtag.Value & "1")
Else
PubTagEntry = vbPubtag.Value
End If
Call InsertNewSliceEntry(SliceEntry, PubTagEntry)
Unload Me
Exit Sub
Err_Execute:
MsgBox "An error occurred."
End Sub
Private Sub vbCancel_Click()
Unload Me
End Sub
Private Sub vbClear_Click()
Call UfNewSlice_Initialize
End Sub
Private Function InsertNewSliceEntry(SliceEntry As String, PubTagEntry As String)
Selection.GoTo what:=wdGoToBookmark, Name:="CuSlSectionEnd"
Dim bmNewSlice As Range, oWd As Word.Application
Set oWd = Word.Application
oWd.Visible = True
Set bmNewSlice = oWd.ActiveDocument.Bookmarks("newSlice").Range
bmNewSlice.Text = SliceEntry
oWd.ActiveDocument.Bookmarks.Add Name:=PubTagEntry, Range:=bmNewSlice
oWd.Selection.GoTo what:=wdGoToBookmark, Name:=PubTagEntry
oWd.Selection.Font.Bold = wdToggle
oWd.Selection.Font.Color = wdColorRed
oWd.Selection.Font.Size = 16
oWd.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
oWd.Selection.MoveDown Unit:=wdLine, Count:=1
oWd.Selection.TypeText Text:=(vbLf & vbLf & vbLf & vbLf)
oWd.Selection.MoveUp Unit:=wdLine, Count:=1
oWd.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
oWd.ActiveDocument.Bookmarks.Add Name:="newSlice"
oWd.Selection.GoTo what:=wdGoToBookmark, Name:="CuSlTOCEnd"
oWd.Selection.MoveLeft Unit:=wdCharacter, Count:=1
oWd.Selection.TypeText Text:=(vbLf & SliceEntry)
oWd.Selection.MoveUp Unit:=wdLine, Count:=1
oWd.Selection.Find.ClearFormatting
With oWd.Selection.Find
.Text = SliceEntry
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
End With
oWd.Selection.Find.Execute
oWd.ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="", _
SubAddress:=PubTagEntry, ScreenTip:="", TextToDisplay:=SliceEntry
Exit Function
End Function
Last edited: