Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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