J
JBNewsGroup
Hi
I have a requirement to draw a Rectangle (using the drawing object) and to
place text centerd
within the Rectangle. I have been able to accomplish this by drawing the
Rectangle, placing a
TextBox within it and then placing a 1 cell Table within that.
I was only able to insert the table by first selecting the Textbox. How do I
set the Table
range (TextBox) without showing that the TextBox was selected? I have tried
various methods
without any success. I am missing something but am not sure what I am
missing. If I do have
to show the "select", how do I "un-select"?
My test code is as follows:
----------------------------------------------------------------------------
---------------------------
Sub TestRectangle()
'
' In Final Version Get Rectangle dimensions
' and location from from Input Form
'
Dim RectL As Integer
Dim RectT As Integer
Dim RectW As Integer
Dim RectH As Integer
Dim BoxL As Integer
Dim BoxT As Integer
Dim BoxW As Integer
Dim BoxH As Integer
Dim RectName As String
Dim TextBoxName As String
Dim InsideText As String
InsideText = "This" & vbCrLf & "Is" & vbCrLf & "Inside" & vbCrLf &
"Text"
RectL = 100
RectT = 20
RectW = 25
RectH = 41
With ActiveDocument.Shapes
BoxL = MillimetersToPoints(RectL)
BoxT = MillimetersToPoints(RectT)
BoxW = MillimetersToPoints(RectW)
BoxH = MillimetersToPoints(RectH)
RectName = .AddShape (msoShapeRectangle, _
BoxL, BoxT, BoxW, BoxH).Name
BoxL = MillimetersToPoints(RectL + 1) ' recalculate, seems
to center Text
BoxT = MillimetersToPoints(RectT + 1) ' box more accurately
BoxW = MillimetersToPoints(RectW - 2)
BoxH = MillimetersToPoints(RectH - 2)
TextBoxName = .AddTextbox(msoTextOrientationHorizontal, _
BoxL, BoxT, BoxW,
BoxH).Name
With .Range(TextBoxName)
.Line.Visible = msoFalse
With .TextFrame
.MarginBottom = 0
.MarginLeft = 0
.MarginRight = 0
.MarginTop = 0
With .TextRange
.Font.Bold = wdToggle
.Font.Name = "Arial"
.Font.Size = 9 ' In final version
adjust text to fit in TextBox
End With
End With
End With
Call PutTextBoxTable (TextBoxName, BoxW, BoxH, InsideText)
.Range (Array(RectName, TextBoxName)).Group
End With
End Sub
----------------------------------------------
----------------------------
Private Sub PutTextBoxTable (TextBoxName As String, _
BoxW As Integer, BoxH As
Integer, _
BoxText As String)
ActiveDocument.Shapes.Range(TextBoxName).Select ' need something
different?
ActiveDocument.Tables.Add _
Range:=Selection.Range, _
NumRows:=1, NumColumns:=1, _
AutoFitBehavior:=wdAutoFitFixed
With Selection.Tables(1)
.Rows.Alignment = wdAlignRowCenter
.TopPadding = 0
.BottomPadding = 0
.LeftPadding = 0
.RightPadding = 0
.AllowAutoFit = False
.AllowPageBreaks = False
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
With .Range
.Rows.SetHeight RowHeight:=BoxH, HeightRule:=wdRowHeightExactly
.Rows.AllowBreakAcrossPages = False
.Cells.SetWidth ColumnWidth:=BoxW, RulerStyle:=wdAdjustNone
.Cells.VerticalAlignment = wdCellAlignVerticalCenter
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Text = BoxText
End With
End With
End Sub
----------------------------------------------------------------------------
---------------------------
Thanks in advance for any help.
Jerry Bodoff
I have a requirement to draw a Rectangle (using the drawing object) and to
place text centerd
within the Rectangle. I have been able to accomplish this by drawing the
Rectangle, placing a
TextBox within it and then placing a 1 cell Table within that.
I was only able to insert the table by first selecting the Textbox. How do I
set the Table
range (TextBox) without showing that the TextBox was selected? I have tried
various methods
without any success. I am missing something but am not sure what I am
missing. If I do have
to show the "select", how do I "un-select"?
My test code is as follows:
----------------------------------------------------------------------------
---------------------------
Sub TestRectangle()
'
' In Final Version Get Rectangle dimensions
' and location from from Input Form
'
Dim RectL As Integer
Dim RectT As Integer
Dim RectW As Integer
Dim RectH As Integer
Dim BoxL As Integer
Dim BoxT As Integer
Dim BoxW As Integer
Dim BoxH As Integer
Dim RectName As String
Dim TextBoxName As String
Dim InsideText As String
InsideText = "This" & vbCrLf & "Is" & vbCrLf & "Inside" & vbCrLf &
"Text"
RectL = 100
RectT = 20
RectW = 25
RectH = 41
With ActiveDocument.Shapes
BoxL = MillimetersToPoints(RectL)
BoxT = MillimetersToPoints(RectT)
BoxW = MillimetersToPoints(RectW)
BoxH = MillimetersToPoints(RectH)
RectName = .AddShape (msoShapeRectangle, _
BoxL, BoxT, BoxW, BoxH).Name
BoxL = MillimetersToPoints(RectL + 1) ' recalculate, seems
to center Text
BoxT = MillimetersToPoints(RectT + 1) ' box more accurately
BoxW = MillimetersToPoints(RectW - 2)
BoxH = MillimetersToPoints(RectH - 2)
TextBoxName = .AddTextbox(msoTextOrientationHorizontal, _
BoxL, BoxT, BoxW,
BoxH).Name
With .Range(TextBoxName)
.Line.Visible = msoFalse
With .TextFrame
.MarginBottom = 0
.MarginLeft = 0
.MarginRight = 0
.MarginTop = 0
With .TextRange
.Font.Bold = wdToggle
.Font.Name = "Arial"
.Font.Size = 9 ' In final version
adjust text to fit in TextBox
End With
End With
End With
Call PutTextBoxTable (TextBoxName, BoxW, BoxH, InsideText)
.Range (Array(RectName, TextBoxName)).Group
End With
End Sub
----------------------------------------------
----------------------------
Private Sub PutTextBoxTable (TextBoxName As String, _
BoxW As Integer, BoxH As
Integer, _
BoxText As String)
ActiveDocument.Shapes.Range(TextBoxName).Select ' need something
different?
ActiveDocument.Tables.Add _
Range:=Selection.Range, _
NumRows:=1, NumColumns:=1, _
AutoFitBehavior:=wdAutoFitFixed
With Selection.Tables(1)
.Rows.Alignment = wdAlignRowCenter
.TopPadding = 0
.BottomPadding = 0
.LeftPadding = 0
.RightPadding = 0
.AllowAutoFit = False
.AllowPageBreaks = False
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
With .Range
.Rows.SetHeight RowHeight:=BoxH, HeightRule:=wdRowHeightExactly
.Rows.AllowBreakAcrossPages = False
.Cells.SetWidth ColumnWidth:=BoxW, RulerStyle:=wdAdjustNone
.Cells.VerticalAlignment = wdCellAlignVerticalCenter
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Text = BoxText
End With
End With
End Sub
----------------------------------------------------------------------------
---------------------------
Thanks in advance for any help.
Jerry Bodoff