Strange behaviour when programmatically adding a background

S

Sean

Hi, I'm adding a background to a Word 2002 doc using the following VB code:

Set lobjPicture =
mWord2000.ActiveDocument.Sections.First.Headers(1).Shapes.AddPicture(mstrTem
plateDir & "\" & lsPictureFilename, False, True, 0, 0, 594, 835)
lobjPicture.LockAnchor = True
lobjPicture.WrapFormat.Type = WdWrapType.wdWrapNone
lobjPicture.Top = -17
lobjPicture.Left = -20
lobjPicture.ZOrder (msoSendBehindText)

When I run this it seems to work ok, however when I send it to the Goldfax
server the background doesn't appear on the fax. That's unless I put a
"DoEvents" and a 3 second delay right after these lines. If I do that then
the background appears on the fax.

Now that we're trying to do this on Citrix (Terminal Server) servers it only
works intermittently. We're going to try increasing the length of the pause,
but it's not a nice solution and could still fail if the server load is
high.

One strange thing is that when I open the docs in Word the ones that worked
have the background appear almost instantly, whereas with the ones that
didn't work there's a delay before the background appears. This must be the
root of the problem, when Goldfax renders the document into a fax it must do
it so quickly that the background hasn't had time to appear.

So basically if I don't pause after adding the background then Word takes a
while to display the background when the document is opened subsequently.
Does anyone have any idea why this is happening?

Many thanks.

Sean
 
C

Cindy M -WordMVP-

Hi Sean,

One of the office.developer groups might be a better place to post this. FWIW,
I was trying to help a C-something developer update code that was written for
Word 97 or 2000 and was also encountering problems with inserting Shapes. In
this case, they were supposed to be positioned at x, y coordinates, and were
instead up at the top, left-hand corner (default position). Turns out that the
problem had to do with a different way the graphics engine was working, and
that he had to use a Sleep command. No way to determine how long he had to let
the system sleep, either.

I suspect you may be encountering the same problem.
Hi, I'm adding a background to a Word 2002 doc using the following VB code:

Set lobjPicture =
mWord2000.ActiveDocument.Sections.First.Headers(1).Shapes.AddPicture(mstrTem
plateDir & "\" & lsPictureFilename, False, True, 0, 0, 594, 835)
lobjPicture.LockAnchor = True
lobjPicture.WrapFormat.Type = WdWrapType.wdWrapNone
lobjPicture.Top = -17
lobjPicture.Left = -20
lobjPicture.ZOrder (msoSendBehindText)

When I run this it seems to work ok, however when I send it to the Goldfax
server the background doesn't appear on the fax. That's unless I put a
"DoEvents" and a 3 second delay right after these lines. If I do that then
the background appears on the fax.

Now that we're trying to do this on Citrix (Terminal Server) servers it only
works intermittently. We're going to try increasing the length of the pause,
but it's not a nice solution and could still fail if the server load is
high.

One strange thing is that when I open the docs in Word the ones that worked
have the background appear almost instantly, whereas with the ones that
didn't work there's a delay before the background appears. This must be the
root of the problem, when Goldfax renders the document into a fax it must do
it so quickly that the background hasn't had time to appear.

So basically if I don't pause after adding the background then Word takes a
while to display the background when the document is opened subsequently.
Does anyone have any idea why this is happening?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
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 :)
 
S

Sean

Thanks Cindy. A couple of days after posting here I also posted in the
word.vba.general group, I haven't had a reply yet though.

At least I'm not the only one to encounter a problem like this (misery loves
company after all). I've found that if I convert the DOC to a PDF then the
background's always included, and without the need for a sleep. As I already
do this for e-mailing the documents I can do the same for faxing and
printing them.

It's a dirty solution but not as dirty as using a pause, especially when the
length of the pause needed would depend on the system load.

I strongly suspect that in the next version of the app we'll be generating
our documents as PDFs in the first place ;-)

Sean
 
S

Sean

I take it back, my dirty solution doesn't work. The PDF conversion involved
creating a virtual printer each time, which took a few seconds. To boost
performance I changed the code to only create the printer before the first
document is converted, and to remove it once the last document has been
done, and suddenly the backgrounds don't always appear. So it seems that it
was the delay from creating the printer that allowed Word to get its act
together. So it probably won't work on Citrix when it's under load.

Oh well, back to the drawing board.

Sean
 
C

Cindy M -WordMVP-

Hi Sean,

Thanks for sharing your experience :) FWIW, the other person I mentioned
opened a bug report with Microsoft (developer level, of course). If enough
developers complain, someone may start paying attention to the issue. I'm not
sure, though, what would be the best way to go. (Opening dev-level support
issues is expensive, I think...)
I take it back, my dirty solution doesn't work. The PDF conversion involved
creating a virtual printer each time, which took a few seconds. To boost
performance I changed the code to only create the printer before the first
document is converted, and to remove it once the last document has been
done, and suddenly the backgrounds don't always appear. So it seems that it
was the delay from creating the printer that allowed Word to get its act
together. So it probably won't work on Citrix when it's under load.

Oh well, back to the drawing board.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
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 :)
 
S

Sean

Thanks Cindy, gotta love the way Microsoft charges you for helping them to
sort out their bugs ;-)

I'm coming at it from the opposite direction now, manually adding the
background image to the template and then programmatically removing it from
the generated document when I don't want it. It's not nice but so far it
seems to be reliable.

Sean
 
C

Cindy M -WordMVP-

Hi Sean,
I'm coming at it from the opposite direction now, manually adding the
background image to the template and then programmatically removing it from
the generated document when I don't want it. It's not nice but so far it
seems to be reliable.
Yes, good thought :)!
gotta love the way Microsoft charges you for helping them to
sort out their bugs ;-)
FWIW, if you come up with something that MS can confirm as a
bug they will refund any charges.

--Cindy
 
Top