Macro Help

M

Michael Koerner

I have the following macro, that someone here provided for me a couple of
years ago. I would like to have the macro when it inserts he header row
character put a dash before and after (-A-) and also make the row height
0.24 high. I have no idea how to do this, and any help would be gratefully
appreciated.


Sub InsertHeaderRow()
Dim Init As String
Dim newrow As Row
Dim dtable As Table
Dim i As Long

If Not Selection.Information(wdWithInTable) Then
MsgBox "You must position the cursor in a table.", _
vbExclamation, "Error"
Exit Sub
End If

Set dtable = Selection.Tables(1)

With dtable
i = 1
Do
If UCase(.Rows(i).Cells(1).Range.Characters(1)) _
<> Init Then
Init = UCase(.Rows(i).Cells(1).Range.Characters(1))
Set newrow = .Rows.Add(.Rows(i))
With newrow
.Cells.Merge
.Cells(1).Range.ParagraphFormat _
.Alignment = wdAlignParagraphCenter
.Range.Text = Init
.Range.Font.Bold = True
.Range.Shading _
.BackgroundPatternColor = wdColorGray10
End With
End If
i = i + 1
Loop While i <= .Rows.Count
End With
End Sub
 
J

Jay Freedman

Replace the line

.Range.Text = Init

with the line

.Range.Text = "-" & Init & "-"

After the BackgroundPatternColor line, add these two lines:

.Height = InchesToPoints(0.24)
.Cells(1).VerticalAlignment = wdCellAlignVerticalCenter

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
M

Michael Koerner

Jay;

Thanks very much, worked like a charm. I neglected to include in my initial
post that I would also like to put a border around that cell. Sorry about
that.
 
J

Jay Freedman

OK, add two more lines after the last ones I showed before:

.Borders.Enable = wdLineStyleSingle
.Borders.OutsideLineWidth = wdLineWidth100pt

You can change the constants for the line style and line width to suit your
preferences.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top