Strange problem with table borders

H

Harald Mueller

Hi,

I encounter a problem with table borders. I wrote a Word macro
which creates a new table with the following parameters:

Set oTable = ActiveDocument.Tables.Add(Selection.Range, NumColumns:=3, NumRows:=1)
With oTable
.Borders.Enable = True
.Borders.InsideLineStyle = wdLineStyleSingle
.Borders.OutsideLineStyle = wdLineStyleSingle
.Columns(1).Width = 100
.Columns(2).Width = 50
.PreferredWidthType = wdPreferredWidthPercent
.PreferredWidth = 100
End With

So I get a table with the width of the entire page, the desired columns and
a border around it. So, if I start the macro out of the Word VB Editor it
runs just fine and I get the correct table.

But the purpose of this macro is that it should run inside an application.
So, if I run it inside the application which uses the Macro, the table is
created with the correct size and columns, but the border is not enabled.

I debugged it and looked at the behavior of oTable.Borders.Enable.
If I run it inside Word it gets set to "-1" at the time the program steps
into the with-block, and the table gets its border. Manually changing
it to 0 (through double-clicking it in the debug window) is possible
and disables the border, manually changing it back to "-1" enables the
border again.

But if I debug it inside the application, it is not possible to change the
value manually. If I set it to something different than 0, it hops back to
0 all the time. The value also gets never ever a different value than 0
programmatically.

So I'm wondering if it is possible to give the Borders.Enable a kind of a
write-protection? The application uses a lot of VBA to export the data
of a different application into a Word document, so could it be something
there, as all is working correctly when used stand-alone but not when called
from the application? I mean, it's hard to imagine that the same code is
working in one place but won't in another.

I'm grateful for every hint what it could be, because I don't know what I could
do now.
 
H

Helmut Weber

Hi Harald,

do you mean
oTable.Borders.Enable = 1 ' or -1, or anything
plus
msgbox oTable.Borders.Enable
results always in 0 ?

And how does the code look from the application?

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
H

Harald Mueller

Hi Helmut,
Hi Harald,

do you mean
oTable.Borders.Enable = 1 ' or -1, or anything
plus
msgbox oTable.Borders.Enable
results always in 0 ?

It is always -1 when started through the "Execute Sub/User Form"
button, which enables the border (quite strange, I always thought
1 would enable it, but it works, so I don't mess with it. In the
code I set "oTable.Borders.Enable = True", which should be usually
1 imho, but as sayed, it works. )

In the debug window, it looks like this:

[ oTable Object/Table ]
|
[ + Borders Borders/Borders]
|
[ + Enable -1 Long ]


msgbox oTable.Borders.Enable always results in "-1" when a table
is created (if executed out of vba) and "0" if started from the
application.
And how does the code look from the application?

Sorry, I can't describe the code from the application. The macro which
creates the tables looks absolutely the same, but the application uses
dozens of other module files to output data from one application into a
Word document. The code for the tables is just used in one place in that
application and there are no other tables used, so I can't say if the
application code messes with tables. I think it could be a problem in one
of those module files, but I don't know what I should look after. I
mean, the table is already generated without borders, and they can't be
enabled. That's odd.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000


Greetings to Bavaria form Bavaria ;)
 
H

Helmut Weber

Hi Harald,

as far as I know and remember,
"true" is not the same or at least wasn't
the same in all programming languages.
Some years ago I was puzzled, too,
to find out that in VB and VBA "true"
was -1, instead of 1, as I was used to.

If you control word from another language,
border.enable is set to the value, which
that language uses for "true".
Therefore my examples did'nt use "true" at all.
Try border.enable = -1, not
border.enable = true.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
H

Harald Mueller

Hi Helmut,

I tried that before and it didn't work either,
but I found a workaround of this problem.

We added a new style with borders and we use it it output
the table text, and it works as it should. That's good enough
for us.

Thanks for your help!

Greetings,
Harald
 

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