Solved

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

Posted on 2007-11-19
8
1,129 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
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

636 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