B
bkleinfi
Hi all,
For the last few days, I have been trying to debug some VBA code and it
is driving me crazy. I'm writting an Excel macro which builds (using
CreateObject) a Word document in background. The document is displayed
at the end of the generation process.
One of the most strange behavior I've noticed is the fact that
everything seems right when I run the code step-by-step in the Visual
Basic editor, but it is screwed up if I execute the macro normally.
For example, I have a sub which insert a table in the document. The
table is supposed to be aligned on the right and be 8 centimeter wide.
If I execute the code step-by-step, displaying the document to watch
the process, the tables will be formatted perfectly. However, if I run
the macro and let the document invisible, the tables will be page wide
and aligned on the left.
The executed code is below:
With MeterTable
.Rows.WrapAroundText = True
.Rows.AllowOverlap = False
.Rows.Alignment = wdAlignRowRight
.PreferredWidthType = wdPreferredWidthPoints
.PreferredWidth = Application.CentimetersToPoints(8.26)
End With
Even better: To tackle this bug, I have tried to add a small loop at
the end of the main macro. the code is below:
For Each aTable In WordDocument.Tables
aTable.Rows.Alignment = wdAlignRowRight
aTable.PreferredWidthType = wdPreferredWidthPoints
aTable.PreferredWidth = Application.CentimetersToPoints(8.26)
Next aTable
WordApplication.Visible = True
' End of the macro
If I do it, the tables are 8.26 centimeter wide, but they are still
aligned on the left !
I have the same kind of problem with images I want to put in the
background of the table: when I am debugging the code, the image fits
perfectly, while it is put in the top left corner of the page if I run
the macro.
Can someone help me, please?! These bugs seem supernatural to me.
-- Ben
For the last few days, I have been trying to debug some VBA code and it
is driving me crazy. I'm writting an Excel macro which builds (using
CreateObject) a Word document in background. The document is displayed
at the end of the generation process.
One of the most strange behavior I've noticed is the fact that
everything seems right when I run the code step-by-step in the Visual
Basic editor, but it is screwed up if I execute the macro normally.
For example, I have a sub which insert a table in the document. The
table is supposed to be aligned on the right and be 8 centimeter wide.
If I execute the code step-by-step, displaying the document to watch
the process, the tables will be formatted perfectly. However, if I run
the macro and let the document invisible, the tables will be page wide
and aligned on the left.
The executed code is below:
With MeterTable
.Rows.WrapAroundText = True
.Rows.AllowOverlap = False
.Rows.Alignment = wdAlignRowRight
.PreferredWidthType = wdPreferredWidthPoints
.PreferredWidth = Application.CentimetersToPoints(8.26)
End With
Even better: To tackle this bug, I have tried to add a small loop at
the end of the main macro. the code is below:
For Each aTable In WordDocument.Tables
aTable.Rows.Alignment = wdAlignRowRight
aTable.PreferredWidthType = wdPreferredWidthPoints
aTable.PreferredWidth = Application.CentimetersToPoints(8.26)
Next aTable
WordApplication.Visible = True
' End of the macro
If I do it, the tables are 8.26 centimeter wide, but they are still
aligned on the left !
I have the same kind of problem with images I want to put in the
background of the table: when I am debugging the code, the image fits
perfectly, while it is put in the top left corner of the page if I run
the macro.
Can someone help me, please?! These bugs seem supernatural to me.
-- Ben