Assuming that you changed the name of the check box from Checkbox1 to Encl, and
also assuming that when the check box is checked you want the code to insert the
abbreviation "Encl." at the bookmark named "Encl", then you need to change these
lines near the end of your code
If (Encl.Value = True) Then
Set oRng = oBM("Encl").Range
oBM.Add "Encl", oRng
Me.Hide
End If
to this:
If (Encl.Value = True) Then
Set oRng = oBM("Encl").Range
oRng.Text = "Encl."
End If
Me.Hide
Here are some things to notice:
- The line Me.Hide should not be between the If and the End If. You want the
userform to hide (which causes control to return to the macro that called the
userform) regardless of whether the check box is checked or not. The way you had
it before, if the check box wasn't checked then the userform would never go
away.
- Proper indenting of code (for example, the lines between If and End If) helps
greatly in seeing how the flow of execution will go. When everything is jammed
against the left margin, it's much harder to understand.
- The line oBM.Add "Encl", oRng in your code would create a bookmark named
Encl that covers the range oRng -- but there is already a bookmark with that
name and range, so this line effectively does nothing. Instead, you need the
line that assigns the text "Encl." to oRng.Text.
- The Option Explicit statement doesn't have anything to do with why your macro
isn't working. It causes VBA to show an error message if you try to use a
variable name that hasn't been defined by a Dim statement (or, for certain
purposes, by a Public statement or a Private statement, but those are more
advanced than you need). Read
http://www.word.mvps.org/FAQs/MacrosVBA/DeclareVariables.htm to find out about
this.
- The procedure named UserForm_Initialize also doesn't have anything to do with
why your macro isn't working. It runs when the userform is first prepared to
show on the screen. In your case, you don't have anything that needs to be done
at that time, so you don't need the procedure at all.
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.