VBA difference Office 2000/XP

T

The Other Roger

I started writing my first VBA for Word program yesterday on my home machine
running Office 2000/W2K. After getting a 0th pass working I moved the program
to my machine at work running Office XP Pro/WXP and the program failed. I am
creating a simple document consisting of a series of text headings followed by
imported EPS pictures. The difference between the 2 Office versions seems to be
that when I have a statement like:
Set myRange = myDoc.Range
In Office 2000 the range includes the text and imported picture whereas in
Office XP Pro the range includes only the text, not the imported picture. Not
only is this a compatibility problem but I can't figure out how to set a range
in Office XP Pro that spans the entire document including the imported picture.

What's going on here?

Roger
 
T

TC

Maybe one of the picures is set to "float over text", ie. it is part of
he Drawing layer, bu the other one does not have that option, so it is
"in line" in the documen?

HTH,
TC
 
R

Roger

No. The situation is that the same program with the same input data behaves
differently in the two environments. With Office 2000 the "end" of the
document is after text and picture whereas with Office XP the "end" is only
after the text.

Roger
 
T

TC

You are using the exact same document file in each case? You are not
recreating it seperatey for each test?

TC
 
P

Peter Huang [MSFT]

Hi Roger,

Have you tried to open the Word 2000 document in Word XP directly and run
the code did you get the same error?
If yes, can you provide a simple reproduce sample docment including your
test code/the test picture together with your reproduce steps?
Thanks for your efforts.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

The Other Roger

Peter,
To clarify, I did not get an error but rather different semantic interpretation
between Word 2000 and Word XP. I include a simple example. In my real code I
am using postscript pictures but for the simple example I created a small BMP
with Paint. The picture was simply a solid rectangle that was 120x56 in size.
I did not include a picture (are attachments permitted in the NG?) but it is
trivial to make the picture I described.

Here is the simple test case. Forgive me if this is lousy VBA code since I am
an absolute newbie:

Sub Grapher()
Dim myDoc As Document
Dim myRange As Range
Dim mark

Documents(1).Activate
Set myDoc = Documents.Application.ActiveDocument
Set myRange = myDoc.Range
mark = myRange.End
Set myRange = myDoc.Range(mark - 1)
myRange.InsertBefore ("Heading 1")
Set myRange = myDoc.Range
myRange.InsertParagraphAfter
Set myRange = myRange.paragraphs(2).Range
myDoc.Shapes.AddPicture "picture.bmp", False, True, , , , , myRange
Set myRange = myDoc.Range
mark = myRange.End
Set myRange = myDoc.Range(mark - 1)
myRange.InsertAfter (vbCrLf)
Set myRange = myDoc.Range
mark = myRange.End
Set myRange = myDoc.Range(mark - 1)
myRange.InsertBefore ("Heading 2")
End Sub

My expected result is "Heading 1" as a line of text followed by the picture
followed by "Heading 2" as a line of text. This is the result I get with Word
2000 running on a W2K machine and Word 97 running on WinNT. However with Word
XP running on an XP Pro machine, "Heading 2" is not visible. It is covered by
the picture. I believe the reason is that Word XP VBA is interpreting the last
4 lines of the function differently than the other versions of Word.

Roger
 
T

Tony Jollans

All versions of Word are little bit different here. In Word 2000 you have no
choice but in Word 2002 (and 3) there is an option under Tools > Options >
Edit tab which controls the way pictures are added. If you set this to "In
line with text" you should get the same behaviour as with Word 2000.

--
Enjoy,
Tony


The Other Roger said:
Peter,
To clarify, I did not get an error but rather different semantic interpretation
between Word 2000 and Word XP. I include a simple example. In my real code I
am using postscript pictures but for the simple example I created a small BMP
with Paint. The picture was simply a solid rectangle that was 120x56 in size.
I did not include a picture (are attachments permitted in the NG?) but it is
trivial to make the picture I described.

Here is the simple test case. Forgive me if this is lousy VBA code since I am
an absolute newbie:

Sub Grapher()
Dim myDoc As Document
Dim myRange As Range
Dim mark

Documents(1).Activate
Set myDoc = Documents.Application.ActiveDocument
Set myRange = myDoc.Range
mark = myRange.End
Set myRange = myDoc.Range(mark - 1)
myRange.InsertBefore ("Heading 1")
Set myRange = myDoc.Range
myRange.InsertParagraphAfter
Set myRange = myRange.paragraphs(2).Range
myDoc.Shapes.AddPicture "picture.bmp", False, True, , , , , myRange
Set myRange = myDoc.Range
mark = myRange.End
Set myRange = myDoc.Range(mark - 1)
myRange.InsertAfter (vbCrLf)
Set myRange = myDoc.Range
mark = myRange.End
Set myRange = myDoc.Range(mark - 1)
myRange.InsertBefore ("Heading 2")
End Sub

My expected result is "Heading 1" as a line of text followed by the picture
followed by "Heading 2" as a line of text. This is the result I get with Word
2000 running on a W2K machine and Word 97 running on WinNT. However with Word
XP running on an XP Pro machine, "Heading 2" is not visible. It is covered by
the picture. I believe the reason is that Word XP VBA is interpreting the last
4 lines of the function differently than the other versions of Word.

Roger
rights.
 
T

The Other Roger

Thanks Tony. Actually "In line with text" is the way the option was set but I
found that by selecting the "Top and bottom" option the code worked the way I
expected.

Roger
 

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