A
Ancient Brit
OK. Another weird one.
I have a need to create a special graphic for users based on limited text
that they type, select, and then click on a button to create. The text is
apparently never more than two characters, usually numeric, occasionally
punctuation.
The graphic is basically a triangle (users call it a "delta") with the text
inside (hopefully fitting neatly).
I did an initial quick n' dirty version that uses the symbol Delta and the
EQ() field, but apparently the unequally thick sides made it unacceptable so
I'm back to the drawing board.
It seemed logical to make use of the AutoShapes' isosceles triangle and add
the text, formatting it appropriately (bold, centered, color-red), but I hit
a snag.
What you can do manually can't it seems be done in VBA, not even if you
record a macro.
Here's the code as it stands (very rough). The user types one or two
characters and then simply selects them, then clicks on a buton to run the
macro. There's a check to see whether anything was actually selected.
....
'Cut the selection to the clipboard for re-insertion later. Test for no
selection:
On Error Resume Next
Selection.Cut
'An error may have been triggered - don't know the details and don't need to
yet
If Err.Number <> 0 Then
MsgBox "DEV: No selection was made. Please try again"
Exit Sub
End If
ActiveDocument.Shapes.AddShape(msoShapeIsoscelesTriangle, 0, 0, _
36, 36).Select
Selection.ShapeRange.TextFrame.TextRange.Select
With Selection
.Collapse
.Paste 'We cut the text above
.WholeStory
.Font.Size = 10
.Font.Bold = True
.Font.Color = wdColorRed
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.ShapeRange.Select
.Cut
End With
Selection.PasteSpecial link:=False, placement:=wdInLine,
dataType:=wdPasteMetafilePicture
....
The idea was to cut the finished graphic with text and then repaste it as a
picture (Windows metafile) formatted as inline so that the user can place it
wherever they need it - in a table, whatever - and it can be resized if
needed to match its surroundings. Manually it works like a charm. (As it
stands, the graphic cannot be formatted as inline unless you cut it and then
repaste as another format).
There's another issue about how to locate the graphic at the current
insertion point when it insists on "floating" but I'll cope with that later.
The PasteSpecial fails - you cannot specify successfully that the graphic
should be pasted inline. Yet when the macro completes, you can select the
graphic and format it as inline - just not in VBA.
Any thoughts, anyone?
Peter
I have a need to create a special graphic for users based on limited text
that they type, select, and then click on a button to create. The text is
apparently never more than two characters, usually numeric, occasionally
punctuation.
The graphic is basically a triangle (users call it a "delta") with the text
inside (hopefully fitting neatly).
I did an initial quick n' dirty version that uses the symbol Delta and the
EQ() field, but apparently the unequally thick sides made it unacceptable so
I'm back to the drawing board.
It seemed logical to make use of the AutoShapes' isosceles triangle and add
the text, formatting it appropriately (bold, centered, color-red), but I hit
a snag.
What you can do manually can't it seems be done in VBA, not even if you
record a macro.
Here's the code as it stands (very rough). The user types one or two
characters and then simply selects them, then clicks on a buton to run the
macro. There's a check to see whether anything was actually selected.
....
'Cut the selection to the clipboard for re-insertion later. Test for no
selection:
On Error Resume Next
Selection.Cut
'An error may have been triggered - don't know the details and don't need to
yet
If Err.Number <> 0 Then
MsgBox "DEV: No selection was made. Please try again"
Exit Sub
End If
ActiveDocument.Shapes.AddShape(msoShapeIsoscelesTriangle, 0, 0, _
36, 36).Select
Selection.ShapeRange.TextFrame.TextRange.Select
With Selection
.Collapse
.Paste 'We cut the text above
.WholeStory
.Font.Size = 10
.Font.Bold = True
.Font.Color = wdColorRed
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.ShapeRange.Select
.Cut
End With
Selection.PasteSpecial link:=False, placement:=wdInLine,
dataType:=wdPasteMetafilePicture
....
The idea was to cut the finished graphic with text and then repaste it as a
picture (Windows metafile) formatted as inline so that the user can place it
wherever they need it - in a table, whatever - and it can be resized if
needed to match its surroundings. Manually it works like a charm. (As it
stands, the graphic cannot be formatted as inline unless you cut it and then
repaste as another format).
There's another issue about how to locate the graphic at the current
insertion point when it insists on "floating" but I'll cope with that later.
The PasteSpecial fails - you cannot specify successfully that the graphic
should be pasted inline. Yet when the macro completes, you can select the
graphic and format it as inline - just not in VBA.
Any thoughts, anyone?
Peter