Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
DerbyDad03 DerbyDad03 is offline
external usenet poster
 
Posts: 48
Default How do I Select an Object with VBA?

I am trying to learn how to Select an object in a Word doc via VBA.

Let me give you an example.

First - I know that I can insert this particular object as an Icon
linked to the file, but if someone can tell me why this conversion
code doesn't work, I'm hoping I'll learn something about selecting
objects via VBA. In other words, this question isn't about the best
way to convert an object, it's about how to select an object.

OK, so I have a new document open. I start the recorder and then
perform these steps:

1 - Go to my desktop
2 - Right click a PDF document and select Copy
3 - Go back into the document and use Edit...Paste
4 - Right-click the object and use the PDF Convert option to create a
PDF Icon
5 - Stop the recorder

This produces the following code:

Sub ConvertToIcon()
Application.WindowState = wdWindowStateNormal
Selection.Paste
ActiveDocument.Shapes("Object 2").Select
If Selection.Type wdSelectionShape Then
Selection.InlineShapes(1).ConvertToShape.Select
End If
Selection.ShapeRange(1).OLEFormat.ConvertTo ClassType:= _
"AcroExch.Document.7", DisplayAsIcon:=True, IconFileName:= _
"C:\WINDOWS\Installer\{AC76BA86-7AD7-1033-7B44-
A90000000001}\PDFFile_8.ico" _
, IconIndex:=0, IconLabel:="Acrobat Document"
End Sub

Now here's the problem: If I copy another PDF and then run this code,
I get an error related to the object not being found, or it tries to
convert the same object over again, etc. Depending on what I've done
before I run the code, the error will change.

It's obvious that it is not selecting the most recently pasted object
because "Object 2" is hard coded. How do I get the code to select the
last object that was pasted without actually knowing what number that
object is?

Thanks.

 
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
can not select an object to delete it from word Associates Microsoft Word Help 3 February 4th 09 05:42 AM
How do I select an object set behind a table? Chris O Tables 1 April 14th 08 04:11 AM
is there any short cut key to select work sheet object in word gkrupanand New Users 1 October 24th 06 06:43 PM
how to set select browser object default ayoung Microsoft Word Help 1 July 5th 06 11:10 PM
Need to select object on background layer in Word 2003. Mike Morrow Page Layout 2 June 30th 05 12:30 AM


All times are GMT +1. The time now is 11:33 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"