AddPicture example works in Word 2000, but not in Word 2003

D

djconner

I have a VB6 application that generates a "transcript" as a Microsoft
Word document. It has been running under Windows 2000/Word 2000, but
now I'm trying to get it to work under Windows XP/Word 2003.

Most everything seems to be OK, but the problem is this bit at the end
of the document, where I have to insert a JPG of a signature between
some boilerplate text. Basically, it looks like:

------
THE ABOVE DATA IS TRUE AND CORRECT.

(signature JPG)

ALPHONSE CAPONE, ASSISTANT MANAGER, CUSTOMER RELATIONS

------

Worked fine for ages with Word 2000, but in Word 2003, it gets messed
up, and the JPG ends up "on top of" the second line of text.

Here's the code I'm using (hope it's readable):

-----
Set oRange =
WordDoc.Range(Start:=WordDoc.Characters(WordDoc.Characters.Count -
1).End, End:=WordDoc.Characters(WordDoc.Characters.Count - 1).End)

oRange.InsertBefore UCase$("This information is determined to be true
and correct.") & vbCrLf & vbCrLf

Set oRange =
WordDoc.Range(Start:=WordDoc.Characters(WordDoc.Characters.Count -
1).End, End:=WordDoc.Characters(WordDoc.Characters.Count - 1).End)

WordDoc.Shapes.AddPicture FileName:=App.Path & "\Capone-Signature.jpg",
LinkToFile:=False, SaveWithDocument:=True, Anchor:=oRange

oRange.InsertAfter "ALPHONSE CAPONE, ASSISTANT MANAGER, CUSTOMER
RELATIONS" & LPad("CERTIFICATION DATE: " & Format$(Now, "MM/DD/YYYY"),
37)
-----

(One thing I just belatedly learned while googling for help on this is
that Word doesn't recognize vbCrLf! Never knew that, but it doesn't
appear to have any bearing on this particular problem.)

What do I need to do to get the JPG to be in the right place, as it is
in Word 2000? Any help would be appreciated!
 
C

Cindy M.

Hi Djconner,

I'm surprised it worked reliably in Word 2000...

Try using the INLINESHAPES.AddPicture rather than the Shapes.AddPicture
method. Word has two ways to work with graphics in a document. The one is
with text-flow formatting (Shape), where the graphic "floats" on the
page. The other is to handle them like any text character (InlineShape).
For what you want, an InlineShape is just the thing.
I have a VB6 application that generates a "transcript" as a Microsoft
Word document. It has been running under Windows 2000/Word 2000, but
now I'm trying to get it to work under Windows XP/Word 2003.

Most everything seems to be OK, but the problem is this bit at the end
of the document, where I have to insert a JPG of a signature between
some boilerplate text. Basically, it looks like:

------
THE ABOVE DATA IS TRUE AND CORRECT.

(signature JPG)

ALPHONSE CAPONE, ASSISTANT MANAGER, CUSTOMER RELATIONS

------

Worked fine for ages with Word 2000, but in Word 2003, it gets messed
up, and the JPG ends up "on top of" the second line of text.

Here's the code I'm using (hope it's readable):

-----
Set oRange =
WordDoc.Range(Start:=WordDoc.Characters(WordDoc.Characters.Count -
1).End, End:=WordDoc.Characters(WordDoc.Characters.Count - 1).End)

oRange.InsertBefore UCase$("This information is determined to be true
and correct.") & vbCrLf & vbCrLf

Set oRange =
WordDoc.Range(Start:=WordDoc.Characters(WordDoc.Characters.Count -
1).End, End:=WordDoc.Characters(WordDoc.Characters.Count - 1).End)

WordDoc.Shapes.AddPicture FileName:=App.Path & "\Capone-Signature.jpg",
LinkToFile:=False, SaveWithDocument:=True, Anchor:=oRange

oRange.InsertAfter "ALPHONSE CAPONE, ASSISTANT MANAGER, CUSTOMER
RELATIONS" & LPad("CERTIFICATION DATE: " & Format$(Now, "MM/DD/YYYY"),
37)
-----

(One thing I just belatedly learned while googling for help on this is
that Word doesn't recognize vbCrLf! Never knew that, but it doesn't
appear to have any bearing on this particular problem.)

What do I need to do to get the JPG to be in the right place, as it is
in Word 2000?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
D

djconner

I actually experimented with InlineShapes before, and it caused even
more problems.

If I replace the current Shapes line with this:

WordDoc.InlineShapes.AddPicture FileName:=App.Path & "\Signature.jpg",
LinkToFile:=False, SaveWithDocument:=True, Range:=oRange

I end up getting the signature... hmm, it's hard to explain, and even
harder for me to understand. The full line that's supposed to be after
the signature is something like:

ALPHONSE CAPONE, ASSISTANT MANAGER, CUSTOMER RELATIONS
CERTIFICATION DATE: 08/18/2006

It ends up putting everything except the date BEFORE the signature,
then the signature, then just the date part, and moving the signature
file over by the width of the date text.

Something like (hope this will show, or at least get the gist across):

ALPHONSE CAPONE, ASSISTANT MANAGER, CUSTOMER RELATIONS
CERTIFICATION DATE:
#########sigfile#########
#########sigfile#########
#########sigfile#########
08/18/2006#########sigfile#########

I'm kind of baffled by this, as the line with certification date ALWAYS
fits into a single line with no trouble - unless I'm messing around
with inline shapes, but it doesn't seem like the two should affect each
other in any way.
 
D

djconner

Experimenting further, I might have found a fix. By putting another
line of:

Set oRange =
WordDoc.Range(Start:=WordDoc.Characters(WordDoc.Characters.Count -
1).End, End:=WordDoc.Characters(WordDoc.Characters.Count - 1).End)

before the "oRange.InsertAfter" line, that seems to put the cursor
where it belongs.

By the way, is there some less horribly clunky way to do that? All I
want is "Move the cursor to the end of the document," but that
kludgy-looking monstrosity is the only way I could find to execute
something that I figure should be a simple and commonly needed task.
 
C

Cindy M.

Hi Djconner,

Yes, working with ranges can be disconcerting until you get used to it.
Think about it like working with a selection, except you can't see it.
So, if you set a range to include text (WordDoc.Content for example),
you need to do the equivalent of pressing the right-arrow key. In the
object model, this is the Collapse method, with the WdCollapseDirection
enum to tell Word whether you want the beginning or the end of the
range.

Set oRange = WordDoc.Content
oRange.Collapse(wdCollapseEnd)

puts the range at the very end of the document.
Experimenting further, I might have found a fix. By putting another
line of:

Set oRange =
WordDoc.Range(Start:=WordDoc.Characters(WordDoc.Characters.Count -
1).End, End:=WordDoc.Characters(WordDoc.Characters.Count - 1).End)

before the "oRange.InsertAfter" line, that seems to put the cursor
where it belongs.

By the way, is there some less horribly clunky way to do that? All I
want is "Move the cursor to the end of the document," but that
kludgy-looking monstrosity is the only way I could find to execute
something that I figure should be a simple and commonly needed task.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top