PDA

View Full Version : Insert "New" WordArt Object Programattically.



gmaxey
09-10-2012, 10:35 AM
Cross posted: http://answers.microsoft.com/en-us/office/forum/office_2010-customize/insert-new-wordart-object-in-word-20102013/48c5d6a1-7aac-4c43-a4c5-9b86b3b85754

http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/9ecd41e6-90bd-4f33-b927-c8d90c24bc54

I've looked around in Google and other forums for a procedure to insert a "New" WordArt object in a Word 2010/2013 document programatically.

The one in the VBA Help file fails and produces a runtime error:
-2147024809 Operation is not supported by the current object
Sub NewCanvasTextEffect()
Dim docNew As Document
Dim shpCanvas As Shape
On Error GoTo Err_Handler:
'Create a new document and add a drawing canvas
Set docNew = Documents.Add
Set shpCanvas = docNew.Shapes.AddCanvas( _
Left:=100, Top:=100, Width:=150, _
Height:=50)

'Add WordArt shape to the drawing canvas
shpCanvas.CanvasItems.AddTextEffect _
PresetTextEffect:=msoTextEffect20, _
Text:="Hello, World", FontName:="Tahoma", _
FontSize:=15, FontBold:=msoTrue, _
FontItalic:=msoFalse, _
Left:=120, Top:=120
Err_Handler:
Debug.Print Err.Number & Err.Description
End Sub

The one at MSDN (this is a version similiar). Does not fail, but the result is really more like and behaves like a "classic" or "old" WordArt oject that you would insert with the UI in Word 2003/2007.

Sub Test()
Dim oRng As Range
Dim oShp As Shape
Set oRng = Selection.Range
Set oShp = ActiveDocument.Shapes.AddTextEffect(Office.MsoPresetTextEffect.msoTextEffec t1, _
"Rotate Me", "Arial", 20, _
Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, 0, 0, oRng)
With oShp
With .Fill
.Solid
.ForeColor.RGB = RGB(0, 0, 0)
End With
End With
End Sub

The "New" WordArt feature inserted with the UI in Word 2010/2013 is capable of being edited and formatted directly in the shape itself. I've tried recording the steps for inserting the object but nothing is recorded. Unless I am missing something, It appears that the methods for producing this object are not in the VBA object.
Has anyone else had success? Thanks

Frosty
09-10-2012, 10:54 AM
I haven't tested this... but if something inserted via the UI is programmatically accessible, then I would stick with the tried and true on handling pseudo-dynamic graphics: create an autotext/building block entry, insert that... and then modify.

I've encountered so many bugs with the dynamic creation of graphic elements in Word 2010, that I won't try it anymore until someone else comes along and tells me it's not a waste of time.

I consistently get application crashes when doing simple Shapes.Add type functions.