Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

Word Macros: Drawing Objects?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rci - 14 Nov 2004 00:52 GMT
Hi all,

tried recording a macro of adding/modifying drawing objects.

The macro recorder simply failed to record anything, and in fact, prevented
me from performing many operations.

What the heck!

Excel does an excellent job of same.

Q:  Are drawing objects even supported by Word VBA?

Specific issue:  I need to add and change the text in a text box, as well as
paste/move an object.

Any help appreciated!

Regards...

SMS
Jean-Guy Marcil - 15 Nov 2004 03:28 GMT
rci was telling us:
rci nous racontait que :

> Hi all,
>
[quoted text clipped - 4 lines]
>
> What the heck!

My macro recorder recorded everything without any problems:
'_______________________________________
Sub Macro1()

ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 126#, _
   108#, 342#, 198#).Select
Selection.ShapeRange.TextFrame.TextRange.Select
Selection.Collapse
Selection.TypeText Text:= _
   "I have created this textbox and typed this text while the macro
recorder was on."
Selection.TypeParagraph
Selection.TypeText Text:= _
   "Now I am going to select this box, cut it, type some text in the main
document and paste the box back in."
Selection.ShapeRange.Select
Selection.Cut
Selection.TypeText Text:="Text in the main document."
Selection.TypeParagraph
Selection.Paste

End Sub
'_______________________________________

> Excel does an excellent job of same.

So does Word!

> Q:  Are drawing objects even supported by Word VBA?

Yes.

> Specific issue:  I need to add and change the text in a text box, as
> well as paste/move an object.
>
> Any help appreciated!

Here is the same macro, rewritten to remove the Selection object as much as
possible.

'_______________________________________
Sub MacroReWorked()

Dim MyBox As Shape
Dim BoxText As Range

With ActiveDocument
   Set MyBox = .Shapes.AddTextbox(msoTextOrientationHorizontal, _
       126#, 108#, 342#, 198#)
   With MyBox
   Set BoxText = .TextFrame.TextRange
       BoxText.Text = "I have created this textbox and typed this text " _
           & " while the macro recorder was on." & Chr(13) _
           & "Now I am going to select this box, cut it, type some text " _
           & "in the main document and paste the box back in."
       .Select
   End With
   Selection.Cut
   .Paragraphs(1).Range.Text = "Text in the main document." & Chr(13)
   Selection.Paste
End With

End Sub
'_______________________________________

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.