I think I've made some considerable progress, but am currently getting an error when I attempt to change between the selections:
This is the entire userform, which has an 2 comboboxes, 1 text box and command button. And the autotext is being store in the 'ReportMacros' file that is loaded at the Word Startup
Code:
Option Explicit
Private Sub CommandButton1_Click()
Selection.TypeText ComboBox2.Value
'Unload Me
End Sub
Private Sub ComboBox1_Change()
Dim index As Integer
Dim objTemplate As Template
Dim oBuildingBlock As BuildingBlock
Dim i As Integer
Dim sPath As String
' Set the template to store the building block
sPath = Environ("APPDATA") & "\Microsoft\Word\STARTUP\ReportMacros.dotm"
Set objTemplate = Templates(sPath)
index = ComboBox1.ListIndex
ComboBox2.Clear
Select Case index
Case Is = 0 'AR Ineligibles
For i = 1 To objTemplate.BuildingBlockEntries.Count
Set oBuildingBlock = objTemplate.BuildingBlockEntries.Item(i)
If oBuildingBlock.Type.Name = "Custom AutoText" And oBuildingBlock.Category.Name = "AR Ineligibles" Then
Me.ComboBox2.AddItem oBuildingBlock.Name
Me.ComboBox2.Column(1, i - 1) = oBuildingBlock.Value
End If
Next i
Me.ComboBox2.Text = Me.ComboBox2.List(0)
Case Is = 1 'Inventory Ineligibles
For i = 1 To objTemplate.BuildingBlockEntries.Count
Set oBuildingBlock = objTemplate.BuildingBlockEntries.Item(i)
If oBuildingBlock.Type.Name = "Custom AutoText" And oBuildingBlock.Category.Name = "Inv Ineligibles" Then
Me.ComboBox2.AddItem oBuildingBlock.Name
Me.ComboBox2.Column(1, i - 1) = oBuildingBlock.Value
End If
Next i
Me.ComboBox2.Text = Me.ComboBox2.List(0)
End Select
End Sub
Private Sub ComboBox2_Change()
TextBox1.Value = ComboBox2.Value
End Sub
Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "AR Ineligibles"
.AddItem "Inv Ineligibles"
End With
Me.ComboBox1.Text = Me.ComboBox1.List(0)
End Sub
Currently, when I attempt to change between AR Ineligible and Inv Ineligible, I get an error message with the Case 1 of the on change event here?
Code:
Me.ComboBox2.Column(1, i - 1) = oBuildingBlock.Value
Again, it is that line in Case 1, and not Case 0
The error Message is
Run Time Error '381'
Could not set the column property Invalid Property Array Index
Can anyone help with that error code?