Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

VBA Help with run time error code 5941


  • Please log in to reply

#1
Shery Keel

Shery Keel

    New Member

  • Member
  • Pip
  • 2 posts
Hello! I am new and on the job as we speak. So, I hope that I am not being redundant with my topic; but I am in quite the hurry. Currently using Word 2007, I have tried to change a bookmark for a check box. All I am trying to do is make the Active X and Form Field Check boxes change from an "x" to a check mark. Below is the VBA I used:

Option Explicit
Sub CheckIt()
Dim oBMs As Bookmarks
Dim oStr As String
Dim oRng As Word.Range
'ActiveDocument.Unprotect'Activate this line if using a protected Word form
Set oBMs = ActiveDocument.Bookmarks
oStr = Selection.Bookmarks(1).Name
Set oRng = oBMs(oStr).Range
ActiveDocument.AttachedTemplate.AutoTextEntries("Check1").Insert Where:=oRng
oBMs.Add oStr, oRng
oRng.Font.Color = wdColorBlack
'ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True'Activate this line as required.
End Sub

Sub UncheckIt()
Dim oBMs As Bookmarks
Dim oStr As String
Dim oRng As Word.Range
'ActiveDocument.Unprotect'Activate this line if using a protected Word form
Set oBMs = ActiveDocument.Bookmarks
oStr = Selection.Bookmarks(1).Name
Set oRng = oBMs(oStr).Range
ActiveDocument.AttachedTemplate.AutoTextEntries("Check2").Insert Where:=oRng
oBMs.Add oStr, oRng
oRng.Font.Color = wdColorAutomatic
'ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True'Activate this line as required.
End Sub

However, when I click on the boxes, I get a dialogue box that says, "Run-time error '5941': The requested member of the collection does not exist"

So, I click on debug and this is what is highlighted:
ActiveDocument.AttachedTemplate.AutoTextEntries("Check1").Insert Where:=oRng

"Check1" is the name of the bookmark for the check box I am trying to use. Is my error in defining parameters for both checked and unchecked at the same time when I should only be defining for one at a time? Or is the error that I need to change "AutoTextEntries(Check1)" to something else. If so, how am I suppose to know what to change it to?
  • 0

Advertisements


#2
Shery Keel

Shery Keel

    New Member

  • Topic Starter
  • Member
  • Pip
  • 2 posts
It shouldn't be this hard. I should just be able to change the bookmark that's already there for the check box form field. What am I missing?
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP