-
Because the WordArt shape automatically sets the width of the object based on it's content, there are two options that I can see:
1. set the width after it's inserted, as johnske suggests - this will distort the text but give you an exact width match
2. if you don't want to distort the text, calculate the expected width of the new wordart, then add spaces until it hits a specified size - this won't be exact in terms of width, within the width of a space of the font/size you use. Hopefully the text distortion would then be minimized[VBA]'left position of inserted wordart, although you could resize the shape at the end if you need an exact width.
Const SHP_LEFT As Single = 100
'max width allowed
Const MAX_SHP_WIDTH As Long = 150
Sub test()
Dim strWAtext As String
Dim shpNewWA As Shape
strWAtext = "Test string 2"
If GetNewWALength(strWAtext) < MAX_SHP_WIDTH Then
Do
strWAtext = strWAtext & " "
Loop Until GetNewWALength(strWAtext) >= MAX_SHP_WIDTH
End If
Set shpNewWA = AddWordArt(strWAtext, 200)
shpNewWA.Width = MAX_SHP_WIDTH
End Sub
Function GetNewWALength(str As String) As Single
' paramater: text of wordart
' returns: expected width of wordart
Dim shpTempWA As Shape
Dim i As Long
Dim totalwidth As Single
For i = 1 To Len(str)
Set shpTempWA = AddWordArt(Mid(str, i, 1), 100)
totalwidth = totalwidth + shpTempWA.Width
shpTempWA.Delete
Next i
GetNewWALength = totalwidth
End Function
Function AddWordArt(str As String, shptop As Single) As Shape
' paramaters: text of wordart, position from top
' returns: inserted wordart shape object
Dim shp As Shape
Set shp = ActiveSheet.Shapes.AddTextEffect( _
msoTextEffect8, str, "Arial", 24#, msoFalse, msoFalse, SHP_LEFT, shptop)
Set AddWordArt = shp
End Function[/VBA]
K :-)

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules