Solved

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

Posted on 2007-11-19
8
1,038 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.

746 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

13 Experts available now in Live!

Get 1:1 Help Now