L
LEU
I have a macro that creates a textbox, inserts one line of text and then
names it. I tried to modify it (see below) to put in two lines of text with
different fonts. I get an error using ‘.TypeParagraph’ for my hard return. If
I remove it and run the macro (to see if the rest of the macro works) it only
gives me the text ‘tep’ in my textbox. What am I doing wrong?
Dim idx As Long, num As Long
Dim CS As Shape
Dim textbox As Shape
Dim aVar As Variant
On Error GoTo endthis
For Each aVar In ActiveDocument.Variables
If aVar.Name = "idx" Then
num = aVar.Index
Exit For
End If
Next aVar
If num = 0 Then
ActiveDocument.Variables.Add Name:="idx", Value:=0
End If
idx = ActiveDocument.Variables("idx").Value + 1
Select Case Selection.Style
Case ActiveDocument.Styles(wdStyleHeading1)
Set CS = ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 15, _
Selection.Information(wdVerticalPositionRelativeToPage) - 3.5, 50, 24)
With CS.TextFrame.TextRange
.Font.Italic = wdToggle
.Font.Size = 12
.Text = "C"
.Font.Size = 8
.Text = "ritical"
.TypeParagraph
.Font.Size = 12
.Text = "S"
.Font.Size = 8
.Text = "tep"
End With
CS.Fill.Visible = msoFalse
CS.Line.Visible = msoFalse
CS.Name = "CS" & idx
ActiveDocument.Variables("idx").Value = idx
endthis:
End Select
names it. I tried to modify it (see below) to put in two lines of text with
different fonts. I get an error using ‘.TypeParagraph’ for my hard return. If
I remove it and run the macro (to see if the rest of the macro works) it only
gives me the text ‘tep’ in my textbox. What am I doing wrong?
Dim idx As Long, num As Long
Dim CS As Shape
Dim textbox As Shape
Dim aVar As Variant
On Error GoTo endthis
For Each aVar In ActiveDocument.Variables
If aVar.Name = "idx" Then
num = aVar.Index
Exit For
End If
Next aVar
If num = 0 Then
ActiveDocument.Variables.Add Name:="idx", Value:=0
End If
idx = ActiveDocument.Variables("idx").Value + 1
Select Case Selection.Style
Case ActiveDocument.Styles(wdStyleHeading1)
Set CS = ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 15, _
Selection.Information(wdVerticalPositionRelativeToPage) - 3.5, 50, 24)
With CS.TextFrame.TextRange
.Font.Italic = wdToggle
.Font.Size = 12
.Text = "C"
.Font.Size = 8
.Text = "ritical"
.TypeParagraph
.Font.Size = 12
.Text = "S"
.Font.Size = 8
.Text = "tep"
End With
CS.Fill.Visible = msoFalse
CS.Line.Visible = msoFalse
CS.Name = "CS" & idx
ActiveDocument.Variables("idx").Value = idx
endthis:
End Select