T
Tristan
Evening all,
As always what I thought would be a nice bit of mental exercise has
evolved into some monster that delights in my frustration and on-coming
headache .
What my little bit of code is trying to do is as follows:
1. The user selects the cells (using the standard Ctrl button and
mouse-click method) which are to be printed in a pre-constructed labels
document in Word
2. The code executes when a control button is activated and registers
the selected cells as an array using the selection object(?) and then
cycles through the array members adding each to its own label in the
document.
Does that make any sense?
Basically I'm trying to turn selected cells into an array and process
them that way.
Well, to my delight the code worked perfectly until I tried
selecting just one cell (i.e. one record) to print.
It seems that VBA won't recognise one-selected cell as an array .
Further testing proved that a non-contiguous selection of cells also
won't be recognised as an array .
I'm at a bit of a loss now and its not a facility I can do without.
Any help will be greatly appreciated.
Thanks Tris
Selection of code below:
Private Sub CommandButton1_Click()
Dim Outputs As Variant
Dim i As Integer
Record_a = Selection.Value
Dim Word As Word.Application
Set Word = New Word.Application
With Word
..ScreenUpdating = False
..Documents.Open Filename:="C:\Documents and
Settings\Label1.doc"
..Visible = True
For i = LBound(Record_a) To UBound(Record_a)
With .Selection
..TypeText Text:=Record_a(i, 1)
..MoveRight unit:=wdCell, Count:=1
End With
Next i
..ScreenUpdating = True
End With
Set Word = Nothing
End Sub
As always what I thought would be a nice bit of mental exercise has
evolved into some monster that delights in my frustration and on-coming
headache .
What my little bit of code is trying to do is as follows:
1. The user selects the cells (using the standard Ctrl button and
mouse-click method) which are to be printed in a pre-constructed labels
document in Word
2. The code executes when a control button is activated and registers
the selected cells as an array using the selection object(?) and then
cycles through the array members adding each to its own label in the
document.
Does that make any sense?
Basically I'm trying to turn selected cells into an array and process
them that way.
Well, to my delight the code worked perfectly until I tried
selecting just one cell (i.e. one record) to print.
It seems that VBA won't recognise one-selected cell as an array .
Further testing proved that a non-contiguous selection of cells also
won't be recognised as an array .
I'm at a bit of a loss now and its not a facility I can do without.
Any help will be greatly appreciated.
Thanks Tris
Selection of code below:
Private Sub CommandButton1_Click()
Dim Outputs As Variant
Dim i As Integer
Record_a = Selection.Value
Dim Word As Word.Application
Set Word = New Word.Application
With Word
..ScreenUpdating = False
..Documents.Open Filename:="C:\Documents and
Settings\Label1.doc"
..Visible = True
For i = LBound(Record_a) To UBound(Record_a)
With .Selection
..TypeText Text:=Record_a(i, 1)
..MoveRight unit:=wdCell, Count:=1
End With
Next i
..ScreenUpdating = True
End With
Set Word = Nothing
End Sub