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 2003

Tip: Looking for answers? Try searching our database.

VBA code no longer works in Office XP

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob U - 29 Oct 2003 20:59 GMT
I am modifying a template previously developed (by someone
else)that inserts an enhanced metafile from the clipboard
and converts it into an inline image. When I use this in
Office XP I get a runtime error 424, object required in
the line marked with ">>>" below. The template worked in
Office 97 and 2000.

If replace = False Then
  mySel.InsertParagraphAfter
End If

On Error GoTo ErrorHandler:
mySel.PasteSpecial Link:=False,
DataType:=wdPasteEnhancedMetafile
On Error GoTo 0

'Can't make a Metafile an InlineShape when inserting so do
it below.
With mySel.ShapeRange
>>>   .PictureFormat.ColorType = msoPictureBlackAndWhite
  .Width = InchesToPoints(6.5)
  .ConvertToInlineShape
End With

Commenting out affected line moves the error to the next
line.

Any insight, advice, or work around will be greatly
appreciated.

TIA

Bob

P.S. ErrorHandler traps non-enhancedmetafiles in the
clipboard...
Jay Freedman - 30 Oct 2003 07:13 GMT
Hi, Bob,

I can tell you what to do to fix the problem, but I can't tell you what
changed or why...

The metafile is being pasted before -- not in -- the range mySel. Running
your code in the debugger with F8 and with mySel.ShapeRange in the Watch
window, you can see that its .Count property is 0, meaning there are no
shapes in the ShapeRange.

To fix this, add this line before the With mySel.ShapeRange statement:

   mySel.MoveStart Unit:=wdCharacter, Count:=-1

That will extend the range one character toward the beginning of the
document, so that it includes the pasted metafile. Now you'll see its .Count
increase to 1, and everything else will work.

Signature

Regards,
Jay Freedman
Microsoft Word MVP     FAQ: http://www.mvps.org/word

> I am modifying a template previously developed (by someone
> else)that inserts an enhanced metafile from the clipboard
[quoted text clipped - 32 lines]
> P.S. ErrorHandler traps non-enhancedmetafiles in the
> clipboard...
Bob U - 30 Oct 2003 16:15 GMT
Jay,

Thanks for responding, however...

I'm still getting the same issue. What you say makes
sence, but I still get the runtime error. Any other ideas?

TIA again.

Bob

>-----Original Message-----
>Hi, Bob,
[quoted text clipped - 53 lines]
>
>.
Jay Freedman - 31 Oct 2003 02:46 GMT
Hi, Bob,

I'm not really sure what's happening in your setup... I'm working with Word
2003, not XP.

It's apparent that the shape's anchor isn't where we expect it to be.
However, it *has to be* somewhere in the same paragraph as the range where
you're pasting it, so this should work:  Remove the mySel.MoveStart
statement and change the With mySel.ShapeRange statement to this:

   With mySel.Paragraphs(1).Range.ShapeRange

Signature

Regards,
Jay Freedman
Microsoft Word MVP     FAQ: http://www.mvps.org/word

> Jay,
>
[quoted text clipped - 70 lines]
>>
>> .
Bob U - 31 Oct 2003 15:57 GMT
Jay,

Thank you again for your prompt response.

This one worked. Like you said, it HAD to be somewhere...

BTW - I checked and it is Office XP and Word 2002 SP-1
(10.3416.3501).

Cheers!
Bob

>-----Original Message-----
>Hi, Bob,
[quoted text clipped - 85 lines]
>
>.
 
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.