![]() |
|
#1
|
|||
|
|||
|
Hi again guys.
(Win7 Word 2010 VBA) I’m creating a Word document using VBA, and I’m placing a table in the document. That works, but there’s too much space around the entries (i.e. the rows are too high). To work out how to code the VBA to correct this I recorded a macro whilst effecting actions which gave me the desired result. Because I can't select the table texts whilst recording the macro I selected the table and then started recording the actions. I pointed the cursor to Home/Line and Paragraph Spacing, clicked on “1.0", then “Remove Space After Paragraph”. The table looks perfect. The following macro was recorded Code:
Sub Macro1()
'
' Macro1 Macro
'
'
Selection.ParagraphFormat.LineSpacing = LinesToPoints(32888)
End Sub
My code follows (N.B. "garsDiner" is a public global string array defined elsewhere) Code:
Public Sub InsertPermDinerArray()
Dim lngCurCol As Long
Dim lngCurRow As Long
Dim lngDinerPtr As Long
Dim lngMaxDiner As Long
Dim lngTotCols As Long
Dim lngTotRows As Long
Dim rng As Range
Dim tblDiner As Table
'*
'** Determine table size (two columns,
'** so number of entries halved then
'** rounded up).
'*
lngMaxDiner = UBound(garsDiner) + 1
lngTotRows = (lngMaxDiner + 0.5) / 2
lngTotCols = 2
'*
'** Prepare to add at the end of the document.
'*
Set rng = ActiveDocument.Content
rng.Collapse Direction:=wdCollapseEnd
'*
'** Insert the table.
'*
With ActiveDocument.Tables
Set tblDiner = .Add(Range:=rng, _
numrows:=lngTotRows, _
numcolumns:=lngTotCols, _
AutoFitBehavior:=wdAutoFitContent)
End With
'*
'** Now populate the table.
'*
lngCurCol = 1
lngCurRow = 1
With tblDiner
For lngDinerPtr = LBound(garsDiner) To UBound(garsDiner)
.Cell(lngCurRow, lngCurCol).Range.InsertAfter garsDiner(lngDinerPtr)
lngCurRow = lngCurRow + 1
If lngCurRow > lngTotRows Then
lngCurRow = 1
lngCurCol = lngCurCol + 1
End If
Next lngDinerPtr
End With
tblDiner.Select
' Macro1 Macro recorded code.
Selection.ParagraphFormat.LineSpacing = LinesToPoints(32888)
Run-time error '5149': The measurement must be between 0.7 pt and 1584 pt. Does anyone know of a way to help me achieve my goal? All assistance gratefully received.... |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Does sending a W10 Word 2016 template to someone with a W7 Word 2010 system cause problems? | dianahbr | Word | 4 | 03-06-2018 02:27 PM |
| Word 2011 for Mac - problems with table of contents | tepose | Word | 1 | 09-28-2014 03:36 PM |
Many Corruption Problems Word 2010
|
sleake | Word | 2 | 07-25-2013 07:20 PM |
| Copy & paste problems Word 2010 | pjm333 | Word | 2 | 02-13-2013 04:52 AM |
Spacing problems with word 2010
|
Microsoftenquirer1000 | Word | 5 | 06-25-2012 12:01 PM |