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 / October 2005

Tip: Looking for answers? Try searching our database.

Add a Floating Shape Anchored to Current Paragraph

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Larry Lutz - 15 Oct 2005 17:57 GMT
I need to set up a macro that will always add a picture as a floating shape
anchored to the current paragraph (where the cursor is located at the time
the function executes). The picture would always be the same file in the
same location. For the life of me, I can't figure out how to do it using the
Help on VBA in Word. I'm currently using Word 2003, but I need for this
macro to work in Word 2000.

The following code is as close as I could get, but it obviously doesn't
accomplish the part about anchoring to the current paragraph:

Dim myPicture As Shape

   With ActiveDocument.Shapes
       Set myPicture = .AddPicture("E:\Documents and Settings\My
Documents\My Pictures\test.jpg", _
           Linktofile = False, Savewithdcoument = True)
       With myPicture.WrapFormat
           .Type = wdWrapSquare
           .Side = wdWrapRight
       End With
       ActiveDocument.Shapes("myPicture").Anchor.Paragraphs(1).Range.Select
   End With

Any help will be most appreciated.

Larry
Tony Jollans - 15 Oct 2005 19:39 GMT
Hi Larry,

You want to anchor the picture when you first pull it in ..

Set myPicture = .AddPicture("E:\Documents and Settings\My Documents\My
Pictures\test.jpg", _
            Linktofile = False, Savewithdcoument = True, _
            Anchor :=Selection.Range)

You might want to anchor it more specifically to the begining of the
paragraph or something, I don't know, but that change will anchor it at the
cursor.

Also lose the ...Shapes("myPicture").Anchor.... line at the end; even if
corrected it is not needed.

--
Enjoy,
Tony

> I need to set up a macro that will always add a picture as a floating shape
> anchored to the current paragraph (where the cursor is located at the time
[quoted text clipped - 16 lines]
>             .Side = wdWrapRight
>         End With

ActiveDocument.Shapes("myPicture").Anchor.Paragraphs(1).Range.Select
>     End With
>
> Any help will be most appreciated.
>
> Larry
Larry Lutz - 15 Oct 2005 20:57 GMT
That worked perfectly! Thanks.

Larry
> Hi Larry,
>
[quoted text clipped - 47 lines]
>>
>> Larry
Tony Jollans - 15 Oct 2005 21:05 GMT
My pleasure!

--
Enjoy,
Tony

> That worked perfectly! Thanks.
>
[quoted text clipped - 50 lines]
> >>
> >> Larry

Rate this thread:






 
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.