Solved

Problem with Selection.Information(wdVerticalPositionRelativeToPage) in MS-Word.

Posted on 2007-11-19
8
1,073 Views
Last Modified: 2008-03-05
I have a VB application which is generating a Word document.  It uses Selection.Information(wdVerticalPositionRelativeToPage) to assist in it's processing.  It works fine when Word is visible and not minimized, but when we minimize Word (for performance reasons - our benchmarks indicate it does generate faster), the information returned is not always correct, causing erroneous processing.  Can you suggest a workaround.  BTW, I did try the Microsoft knowledgebase, but didn't find anything.
0
Comment
Question by:srlapides
  • 4
  • 3
8 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 20312243
Try using a range object instead of the Selection object. (Always a good idea).
0
 
LVL 12

Expert Comment

by:geneus
ID: 20312254
If you are looking to speed up your macro processing I typically Turn Off Screen Updating:

        Application.ScreenUpdating = False

Then turn it back on at the end of processing:

    'Manually Refreshes the Screen
        Application.ScreenRefresh

    'Restarts Screen Refreshing
        Application.ScreenUpdating = True

For more information try this article too:

How to speed up Word Automation by hiding the application
http://word.mvps.org/FAQs/InterDev/MakeAppInvisible.htm

NOTE:  Do not Minimize the Screen using the ScreenRefresh as it will not benefit further
0
 

Author Comment

by:srlapides
ID: 20313102
I got the same erroneous result using the Range object.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 20313343
What sort of inaccuracies are they?

Perhaps we should be sure that your Word installation is working correctly, so try these troubleshooting steps.

http://www.officearticles.com/word/steps_to_troubleshooting_microsoft_word.htm
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:srlapides
ID: 20313414
What happens is that the Selection (or Range).Information is incorrect.  We use wdVerticalPositionRelativeToPage to determine when to take a page break, so we can regenerate headers and subheaders.  I've used debug.print to see what's happening - it returns a high enough value that our report starts taking page breaks every line.  To repeat, this happens only when Word is minimized.  

Here's an excerpt from another entry in your Knowledgebase with the same observation (see the last line):

-----------------------------------------------------------------------------------------------------------------------------

Question: I have a big problem with this functionality.
I need to use it ,because ,I create a lot of tables(dinamicly) in Word Document (in VB code)
And I check :
--------------------------------------------------------------------------------------------
If (objDoc.ActiveWindow.Selection.Information(wdVerticalPositionRelativeToPage) > 410) Then
    objDoc.ActiveWindow.Selection.InsertBreak Type:=wdPageBreak
End If
-------------------------------------------------------------------------------------------
It's mean I want to  start a new table on the new page if it's remain a little piece on current page.

But when it's become 488(i Don't know how,because it's already a new page ),after that it's not change never.And always equal to 488 .How can I solve this ,that this functionality will work correctly.
May be somebody had same  problem.
Or maybe somebody has a new solution .Please help me ,it's very urgent for me !!!

p.s. Document must be unvisible .I checked if the Document is visible ,it's work right ?!?!?!?!?
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 20313887
Perhaps a frequent Repaginate call will help with the accuracy (though not with the performance)

Note that there is built-in paragraph and other formatting functionality such as Widow-control and Keep Together/With Next that might be able to do that sort of job automatically.
0
 

Author Comment

by:srlapides
ID: 20315517
The long and short of it is that this is a long standing Microsoft bug that we're all trying to work around.  I don't like turning off ScreenUpdating (I admit it's a performance improvement to do so) but if there's a crash with no error recovery, then the Word window is empty space.  And you get the same effect by selecting it in the taskbar list while it's generating.  Pretty ugly.

I had already tried RePaginate but that didn't help either.  But the code below does seem to work.  We offer the user an option to do alternate row shading for readability - when we do that, we never see the problem.  When alternate shading is not selected, we now still go though the mechanics of doing it - that seems to work, though it is a performance hit.  I was hoping for some other sequence of instructions for the no shading environment that was more efficient.  Here's the code we're using:

    With MyWP.Selection
        .EndKey Unit:=wdLine, Extend:=wdExtend
        With .ParagraphFormat.Shading
            LineCount = LineCount + 1
            .ForegroundPatternColor = wdColorAutomatic
            .BackgroundPatternColor = wdColorAutomatic
            If Not NoShading And LineCount Mod 2 = 1 Then
                .Texture = wdTexture10Percent
            Else
                .Texture = wdTextureNone
            End If
        End With
        .Collapse 0
    End With
    Return
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 50 total points
ID: 20318495
Does it help if you hide the application it by moving the window off-screen?

SaveTop =Application.ActiveWindow.Top = 3000

Application.ActiveWindow.Top = 3000
'do processing

Application.ActiveWindow.Top = SaveTop

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now