Set a Range

  • Thread starter Patrick Simonds
  • Start date
P

Patrick Simonds

I have all of these Ranges to set:

Set INSN1Range = ActiveDocument.BookMarks("Insurance1Address").Range
Set INSN2Range = ActiveDocument.BookMarks("Insurance2Address").Range
Set EffecDate1Range = ActiveDocument.BookMarks("Insurance1Effective").Range
Set EffecDate2Range = ActiveDocument.BookMarks("Insurance2Effective").Range
Set INSID1Range = ActiveDocument.BookMarks("Insurance1ID").Range
Set INSID2Range = ActiveDocument.BookMarks("Insurance2ID").Range
Set INSYesRange = ActiveDocument.BookMarks("InsuranceYes").Range
Set INSNoRange = ActiveDocument.BookMarks("InsuranceNo").Range
Set INSEmployerRange = ActiveDocument.BookMarks("InsuranceEmployment").Range


And I need to set them for each of 10 OptionButtons. I was hoping to save
the time and space of replicating this for each of the 10 OptionButtons so I
created a module:

Public Sub SetBookMarkRange()

Set INSN1Range = ActiveDocument.BookMarks("Insurance1Address").Range
Set INSN2Range = ActiveDocument.BookMarks("Insurance2Address").Range
Set EffecDate1Range = ActiveDocument.BookMarks("Insurance1Effective").Range
Set EffecDate2Range = ActiveDocument.BookMarks("Insurance2Effective").Range
Set INSID1Range = ActiveDocument.BookMarks("Insurance1ID").Range
Set INSID2Range = ActiveDocument.BookMarks("Insurance2ID").Range
Set INSYesRange = ActiveDocument.BookMarks("InsuranceYes").Range
Set INSNoRange = ActiveDocument.BookMarks("InsuranceNo").Range
Set INSEmployerRange = ActiveDocument.BookMarks("InsuranceEmployment").Range

End Sub

I then placed the line BookMarks.SetBookMarkRange at the beginning of each
of the OptionButtons click routines, but I get an error which in effect says
that the range is not set. Any ideas?
 
J

Jezebel

If 'INSN1Range' are global variables, setting them repeatedly has no effect
unless you are redefining the bookmarks. If they are local variables, the
error message is telling you that it doesn't know what they refer to. Read
Help on variable scope.

But more fundamentally, what on earth are you trying to do? The ranges are
already defined (by the bookmarks). Why not just remember the bookmark name?
Then you wouldn't need to do anything at all for your 10 option buttons.
 
P

Patrick Simonds

Okay I'm a novice here. I was just following earlier advice. What do you
mean by "remember the bookmark"?

I thought I had to define a range for each bookmark and then set the range
to the active document. When I click on an OptionButton text is placed at
the bookmark. That text is determined by which OptionButton is selected.
 
J

Jezebel

A bookmark IS a range.

If I understand you rightly, clicking Option button X means 'insert this
text at bookmark Y'. To do that all you need is the name of the bookmark,
not all these references to the bookmark ranges --

Sub Opt_Insurance1_Click()
ActiveDocument.BookMarks("Insurance1ID").Range = "blah blah blah"
End Sub

However, for this sort of purpose, document properties are much easier to
work with than bookmarks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top