PDA

View Full Version : Solved: Deleting Range which is between 2 bookmarks



PKisielewski
03-28-2008, 09:40 AM
I have a form that has a ActiveX combo box which is populated by the Document Open sub:


cbo_DocBase1.AddItem "Select DocBase"
cbo_DocBase1.AddItem "Item 1"
cbo_DocBase1.AddItem "Item 2

Below the combo box I have inserted a bookmark (docbase)

When the user selects from the dropdown selection an onchange event goes to the docbase bookmark location - Inserts bookmark titled begin, inserts checkboxes with corresponding text and inserts a bookmark titled end. I would like for these 2 bookmarks (begin and end), the checkboxes and corresponding text to become a range so that if the user selects anything else in the combo box they will be deleted - kind of like a reset. For example, If the user selects Item 2 (I have not included any code for that) after they already select 1 - the items will be deleted and bookmarks begin, end, the new checkboxes will be populated. The code belows includes - if the user selects "Specify DocBase" selection and I need to add the code for Item 2 which I have not completed as of yet.

Code for on change event is as follows:


If cbo_DocBase1.Text = "Item1" Then
Selection.GoTo What:=wdGoToBookmark, Name:="docclass"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
Selection.TypeText Text:=" "
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="begin"
.DefaultSorting = wdSortByName
.ShowHidden = True
End With

Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormCheckBox
Selection.TypeText Text:=" Master Batch Record Documents"
Selection.TypeParagraph
Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormCheckBox
Selection.TypeText Text:=" Validation Documents"

Selection.TypeText Text:=" "
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="end"
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
End If

If cbo_DocBase1.Text = "Specify DocBase" Then
Selection.GoTo What:=wdGoToBookmark, Name:="docclass"

Dim aRange
Set aRange = ActiveDocument.Range( _
Start:=ActiveDocument.Bookmarks("begin").Range.Start, _
End:=ActiveDocument.Bookmarks("end").Range.End)
aRange.Range.Delete
End If
End Sub


The text in Red does not work - but it seems logical and maybe I am missing something.

Hopefully I have explained my situation.
Thanks in advance for your help.

edit Lucas: When posting code please select the code and hit the vba button so it will be formatted correctly.

Tinbendr
03-28-2008, 10:32 AM
Change
aRange.Range.Delete

to
aRange.Delete

lucas
03-28-2008, 10:37 AM
This seems to work. Change:
aRange.Range.Delete
to:
aRange.Delete

lucas
03-28-2008, 10:40 AM
Looks like my neighbor in Mississippi beat me to it........sorry tinbendr. Does your username mean you work in the sheet metal industry?

PKisielewski
03-28-2008, 11:44 AM
Yeah - This works - Thanks for the quick answer.
I did try the aRange.Delete

myself but I must have had it listed incorrectly.
Thanks tinbendr for your help.
:beerchug:

Tinbendr
04-01-2008, 02:22 PM
tinbendr, Does your username mean you work in the sheet metal industry?I was a aircraft sheetmetal mechanic for twenty years. I push paper around now.

You'll notice the last 'E' missing. When I signed up for QuantumLink with my Commodore 64, they only allowed 8 characters, hence the missing 'E'.

lucas
04-01-2008, 02:50 PM
When I signed up for QuantumLink with my Commodore 64, they only allowed 8 characters, hence the missing 'E'.


Whoa, telling both of our ages now.........back when a floppy was floppy..

fumei
04-02-2008, 10:59 AM
and we were using 300 baud modems