Solved

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

Posted on 2007-11-19
8
1,107 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…

749 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