G
Greg
Hi,
I am getting an Error in some code that I can't understand. The error
is as shown in the subject and when I press "Help" in the message box a
screen reports information ofn Automation Error (440)
which I don't understand.
Here is the scenario. I was goofying around attempting to make
mutually exclusive checkboxes in a simple unprotected form. I was
bored so please bear with me ;-).
I inserted five AutoText entries similiar to the ones available in the
Fax Templates (Checked and Unchecked box symbols nested in a
Macrobutton field)in columns 1 through five across the top of table. My
thinking being that I would use the checkit (I called it enable) macro
to determine column number of the box I checked, toggle the box to
checked, and replace the AutoText entry in the other four columns to
the unchecked box symbol.
In practice, it works pretty good and a working macro is provided
below. The part I can't understand is why I can't use a predefined
range to insert the AutoText in the four other columns.
For some reason I first have to delete the existing AutoText Entry
(using a Range.Delete), then select insertion point (using a
Range.Select) and finally insert the AutoText entry using
Where:=Selection.Range
Here is a short snipet of what I tried to do when the box in column 1
was checked:
Dim oCol1 As Range
'Repeat for oCol2-5
Set oCol1 = ActiveDocument.Tables(1).Cell(1,1).range
'Repeat for oCol2-5
Select Case j 'Column index
Case Is = 1 'Column 1 checkbox checked
oTemp.AutoTextEntries("Disabled").Insert Where:=oCol2
oTemp.AutoTextEntries("Disabled").Insert Where:=oCol3
'repeat for columns 4 and 5
'ERROR is generating on the first oTemp line. Why?
and here is what I had to do:
Select Case j
Case Is = 1
oCol2.Delete
oCol2.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol3.Delete
oCol3.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
'repeat for columns 4 and 5
Option Explicit
Private j As Long
Dim oTemp As Template
Sub Enable()
Dim oCol1 As Range
Dim oCol2 As Range
Dim oCol3 As Range
Dim oCol4 As Range
Dim oCol5 As Range
Dim oTable As Table
Set oTable = ActiveDocument.Tables(1)
Set oTemp = ActiveDocument.AttachedTemplate
Set oCol1 = oTable.Cell(1, 1).Range
Set oCol2 = oTable.Cell(1, 2).Range
Set oCol3 = oTable.Cell(1, 3).Range
Set oCol4 = oTable.Cell(1, 4).Range
Set oCol5 = oTable.Cell(1, 5).Range
j = Selection.Information(wdStartOfRangeColumnNumber)
oTemp.AutoTextEntries("Enabled").Insert Where:=Selection.Range
Select Case j
Case Is = 1
oCol2.Delete
oCol2.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol3.Delete
oCol3.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol4.Delete
oCol4.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol5.Delete
oCol5.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
Case Is = 2
oCol1.Delete
oCol1.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol3.Delete
oCol3.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol4.Delete
oCol4.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol5.Delete
oCol5.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
Case Is = 3
oCol1.Delete
oCol1.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol2.Delete
oCol2.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol4.Delete
oCol4.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol5.Delete
oCol5.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
Case Is = 4
oCol1.Delete
oCol1.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol2.Delete
oCol2.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol3.Delete
oCol3.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol5.Delete
oCol5.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
Case Is = 5
oCol1.Delete
oCol1.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol2.Delete
oCol2.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol3.Delete
oCol3.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol4.Delete
oCol4.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
Case Else
'Do Nothing
End Select
End Sub
Sub Disable()
Set oTemp = ActiveDocument.AttachedTemplate
j = Selection.Information(wdStartOfRangeColumnNumber)
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
End Sub
Thanks
I am getting an Error in some code that I can't understand. The error
is as shown in the subject and when I press "Help" in the message box a
screen reports information ofn Automation Error (440)
which I don't understand.
Here is the scenario. I was goofying around attempting to make
mutually exclusive checkboxes in a simple unprotected form. I was
bored so please bear with me ;-).
I inserted five AutoText entries similiar to the ones available in the
Fax Templates (Checked and Unchecked box symbols nested in a
Macrobutton field)in columns 1 through five across the top of table. My
thinking being that I would use the checkit (I called it enable) macro
to determine column number of the box I checked, toggle the box to
checked, and replace the AutoText entry in the other four columns to
the unchecked box symbol.
In practice, it works pretty good and a working macro is provided
below. The part I can't understand is why I can't use a predefined
range to insert the AutoText in the four other columns.
For some reason I first have to delete the existing AutoText Entry
(using a Range.Delete), then select insertion point (using a
Range.Select) and finally insert the AutoText entry using
Where:=Selection.Range
Here is a short snipet of what I tried to do when the box in column 1
was checked:
Dim oCol1 As Range
'Repeat for oCol2-5
Set oCol1 = ActiveDocument.Tables(1).Cell(1,1).range
'Repeat for oCol2-5
Select Case j 'Column index
Case Is = 1 'Column 1 checkbox checked
oTemp.AutoTextEntries("Disabled").Insert Where:=oCol2
oTemp.AutoTextEntries("Disabled").Insert Where:=oCol3
'repeat for columns 4 and 5
'ERROR is generating on the first oTemp line. Why?
and here is what I had to do:
Select Case j
Case Is = 1
oCol2.Delete
oCol2.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol3.Delete
oCol3.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
'repeat for columns 4 and 5
Option Explicit
Private j As Long
Dim oTemp As Template
Sub Enable()
Dim oCol1 As Range
Dim oCol2 As Range
Dim oCol3 As Range
Dim oCol4 As Range
Dim oCol5 As Range
Dim oTable As Table
Set oTable = ActiveDocument.Tables(1)
Set oTemp = ActiveDocument.AttachedTemplate
Set oCol1 = oTable.Cell(1, 1).Range
Set oCol2 = oTable.Cell(1, 2).Range
Set oCol3 = oTable.Cell(1, 3).Range
Set oCol4 = oTable.Cell(1, 4).Range
Set oCol5 = oTable.Cell(1, 5).Range
j = Selection.Information(wdStartOfRangeColumnNumber)
oTemp.AutoTextEntries("Enabled").Insert Where:=Selection.Range
Select Case j
Case Is = 1
oCol2.Delete
oCol2.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol3.Delete
oCol3.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol4.Delete
oCol4.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol5.Delete
oCol5.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
Case Is = 2
oCol1.Delete
oCol1.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol3.Delete
oCol3.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol4.Delete
oCol4.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol5.Delete
oCol5.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
Case Is = 3
oCol1.Delete
oCol1.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol2.Delete
oCol2.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol4.Delete
oCol4.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol5.Delete
oCol5.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
Case Is = 4
oCol1.Delete
oCol1.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol2.Delete
oCol2.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol3.Delete
oCol3.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol5.Delete
oCol5.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
Case Is = 5
oCol1.Delete
oCol1.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol2.Delete
oCol2.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol3.Delete
oCol3.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
oCol4.Delete
oCol4.Select
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
Case Else
'Do Nothing
End Select
End Sub
Sub Disable()
Set oTemp = ActiveDocument.AttachedTemplate
j = Selection.Information(wdStartOfRangeColumnNumber)
oTemp.AutoTextEntries("Disabled").Insert Where:=Selection.Range
End Sub
Thanks