movedown method

D

Dinçer

Hi everyone!

My program creates a report (Word document) which includes several tables.
Unfortunately, today, I found out that Microsoft has a bug when using
MoveDown method.

(http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com
:80/support/kb/articles/q235/8/76.asp&NoWebContent=1)

The article says the bug doesn't appear if we make the document visible
before using MoveDown method. Indeen, it doesn't.
However, it is not a good thing to show the user all the creation process of
the report.
How can I skip this error and create my reports?

Thank you...

PS:
This line of code is the reason of the problem:
objDoc.ActiveWindow.Selection.MoveDown Unit:=wdLine, Count:=1

What can I do instead of this code, to be able to finish a table and after
putting a few newline's go to the other table?
 
D

Dinçer

I tried this:
I made the document visible before each MoveDown usage, and then I made the
document back invisible.
When run in visible mod, MoveDown works OK.
But, for each table the screen kinda blinks you. And of course, I don't want
this..
Are there any other solution ??
 
P

Peter Hewett

Hi Dinçer

The KB article lists two workarounds. The first make Word visible is not
nice!!! However, they do list a second method. With their example the
method that fails is:

Selection.MoveDown wdLine, 2, wdExtend

and the workaround is:

doc.Range(Start:=doc.Tables(1).Cell(1, 1).Range.Start, _
End:=doc.Tables(1).Cell(3, 1).Range.End).Select

Are you able to use this second method (explicit range selection). There is
yet another possible workaround that Microsoft don't list if you can move
by something other than line (wdLine). You could use a Range object (not
the Selection object) and move that the required number of units. I haven't
tried this but in principle it should be OK, and it's pretty easy to test!

You don't actually say what you are trying to do and what the layout of
your document is, so as you can appreciate it's pretty difficult to give
you a more specific answer.

HTH + Cheers - Peter
 
D

Dinçer

Hi Peter,

I use mostly the Selection pbject, and I don't know if the range object is
applicable to my code.

What I am trying to do is this:
I need several tables in the document. I create one, fill in the necessery
values(from database) in to it. After finishing it, I <move down>, then
leave a few lines, and start another table. The main code is like this:

objDoc.ActiveWindow.Selection.Tables.Add objWord.Selection.Range, 1,
1, wdWord9TableBehavior
objDoc.ActiveWindow.Selection.Tables(1).Cell(1, 1).Width = 425
objDoc.ActiveWindow.Selection.Tables(1).Rows.Alignment =
wdAlignRowCenter
objDoc.ActiveWindow.Selection.ParagraphFormat.Alignment =
wdAlignParagraphLeft
objDoc.ActiveWindow.Selection.Font.Bold = 1
objDoc.ActiveWindow.Selection.TypeText "EXAMPLE DATA"
objDoc.ActiveWindow.Selection.MoveRight Unit:=wdCell
objDoc.ActiveWindow.Selection.MoveDown Unit:=wdLine, Count:=1
objDoc.ActiveWindow.Selection.TypeParagraph
objDoc.ActiveWindow.Selection.TypeParagraph
....
now, another table comes in the same way..
But the line with movedown makes it impossible to create the tables when
visible is false.

How can I rewrite that line, by using Range object instead of Selection
object?

Regards..
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Do something like the following:

Dim mytable As Table, myrange As Range
Set mytable = ActiveDocument.Tables.Add(Selection.Range, 1, 1)
With mytable
.Cell(1, 1).Width = 425
.Rows.Alignment = wdAlignRowCenter
.Cell(1, 1).Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
.Cell(1, 1).Range.Text = "EXAMPLE DATA"
.Cell(1, 1).Range.Font.Bold = True
End With
Set myrange = mytable.Range
myrange.End = myrange.End + 1
myrange.Collapse wdCollapseEnd
myrange.InsertAfter vbCr & vbCr
myrange.End = myrange.End + 2
myrange.Collapse wdCollapseEnd
Set mytable = ActiveDocument.Tables.Add(myrange, 1, 1)


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
P

Peter Hewett

Hi

Check out the following code it produces the same output as you sample but
does not use the selection object and the "MoveDown wdLine" method (which
is not available to a Range object). The code uses an object wdApp but
you'll have to set this up youself as I don't now how your instantiating
Word:

Public Sub InsertStuffTest()
Dim rngInsert As Word.Range
Dim wdApp As Word.Application

Set wdApp = Word.Application
Set rngInsert = wdApp.Selection.Range
With rngInsert
.Tables.Add rngInsert, 2, 1, wdWord9TableBehavior
.Tables(1).Cell(1, 1).Width = 425
.Tables(1).Rows.Alignment = wdAlignRowCenter
.ParagraphFormat.Alignment = wdAlignParagraphLeft
.Text = "EXAMPLE DATA"
.Font.Bold = True
End With

' Insert two new paragraphs at the end of the document
Set rngInsert = ActiveDocument.Content
rngInsert.Collapse wdCollapseEnd
rngInsert.InsertAfter vbCr & vbCr
End Sub

Note that the methods and properties used in the above are different, as
the Range object does not support some of the Selection objects methods and
properties. This should be enough to get you going.

HTH + Cheers - Peter
 

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