Textbox help

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
 
D

Doug Robbins - Word MVP on news.microsoft.com

Use

.Text = "Critical" & vbCr & "Step"
Set crange = .Words(1)
crange.Start = crange.Start + 1
crange.Font.Size = 8
Set crange = .Words(3)
crange.Start = crange.Start + 1
crange.Font.Size = 8


in place of

.Text = "C"
.Font.Size = 8
.Text = "ritical"
.TypeParagraph
.Font.Size = 12
.Text = "S"
.Font.Size = 8
.Text = "tep"


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

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