Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-08-2015, 09:34 AM
drussell drussell is offline Word.WdInformation Windows 7 32bit Word.WdInformation Office 2010 32bit
Novice
Word.WdInformation
 
Join Date: Dec 2015
Posts: 3
drussell is on a distinguished road
Default Word.WdInformation

Have to print a monthly 1000 page txt file. Unfortunately, not all pages end with a page break, as some lines from the next page appear on the previous page.
Each page concludes with a line of asterisks. Created a Word macro, looking for the line of asterisks and if found, tested if the next line contained text from the following page. If so, an insert page break would occur.
The macro works, but now I would like to convert into vbscript.
Started my vbscript by performing the following
Opened file and then tried running the following line from my macro and it does not work
CurrentPagnr = Selection.Information(wdActiveEndPageNumber) ‘checks for current page
After looking up solutions online, someone suggested using the following library (Word.wdInformation), since I am no longer using the Word macro.
Word.wdInformation.wdActiveEndPageNumber instead of Selection.Information
Here is the new line I have tried in many variations
Set objWord = CreateObject(“Word.Application”)
CurrentPagnr = objWord.Selection.Information(Word.WdInformation.w dActiveEndPageNumber) ‘objWord is
This does not work, giving me the following error message
Microsoft VBScript runtime error: Variable is undefined: 'Word'



Any suggestions
Reply With Quote
  #2  
Old 12-08-2015, 03:04 PM
macropod's Avatar
macropod macropod is offline Word.WdInformation Windows 7 64bit Word.WdInformation Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Word.WdInformation would be meaningless, as would Word.wdInformation.wdActiveEndPageNumber. Since you're using late binding, you should be using objWord.Selection.Information(3), since 3 = wdActiveEndPageNumber.

That said, the fact you're even using Selection suggests the code is quite inefficient - there is very little one would need to do in VBA/VBS that requires anything to be selected.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 12-08-2015, 04:37 PM
drussell drussell is offline Word.WdInformation Windows 7 32bit Word.WdInformation Office 2010 32bit
Novice
Word.WdInformation
 
Join Date: Dec 2015
Posts: 3
drussell is on a distinguished road
Default

So how would you check the end of page without using Selection. Your solution helped, as now it appears to work
Where would I find a link to the Numeric Values for Selection.Information and Selection.InsertBreak. As you stated wdActiveEndPageNumber=2
Reply With Quote
  #4  
Old 12-08-2015, 04:57 PM
macropod's Avatar
macropod macropod is offline Word.WdInformation Windows 7 64bit Word.WdInformation Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Without seeing the rest of your code, I can't tell you what you need to change to make it more efficient.

If you want to find the enumeration constants for Information, InsertBreak, etc., look in the Word VBA help file.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 12-09-2015, 08:22 AM
drussell drussell is offline Word.WdInformation Windows 7 32bit Word.WdInformation Office 2010 32bit
Novice
Word.WdInformation
 
Join Date: Dec 2015
Posts: 3
drussell is on a distinguished road
Default

Could not find any information on the Information, or InsertBreak Help file
Here is what I did. Opened up Visual Basic Editor-Help-Microsoft Visual Basic for Application Help. Included a screenshot of
Sorry, there are no results for
InsertBreak

Also tested this for Enumeration, Constants, Information and same result. I am using MS Word 2010.

I also included the script in another attachment. Just curious how you would iterate through the Word Document using vbscript other than using .Selection

Thanks for your assistance
Attached Files
File Type: docx InsertBreak Screenshot.docx (32.1 KB, 7 views)
File Type: docx VBSscript.docx (14.6 KB, 8 views)
Reply With Quote
  #6  
Old 12-09-2015, 01:47 PM
macropod's Avatar
macropod macropod is offline Word.WdInformation Windows 7 64bit Word.WdInformation Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

With some code for Selection.Information in the VBE, I clicked on 'Information' and pressed F1. Up popped:
Quote:
Word Developer Reference
Selection.Information Property

Returns information about the specified selection. Read-only Variant.
Syntax
expression.Information(Type)
expression Required. A variable that represents a Selection object.

Parameters
Name Required/Optional Data Type Description
Type Required WdInformation The information type.

Example

This example displays the current page number and the total number of pages in the active document.
Visual Basic for Applications
MsgBox "The selection is on page " & _
Selection.Information(wdActiveEndPageNumber) & " of page " _
& Selection.Information(wdNumberOfPagesInDocument)

If the selection is in a table, this example selects the table.
Visual Basic for Applications
If Selection.Information(wdWithInTable) Then _
Selection.Tables(1).Select

This example displays a message that indicates the current section number.
Visual Basic for Applications
Selection.Collapse Direction:=wdCollapseStart
MsgBox "The insertion point is in section " & _
Selection.Information(wdActiveEndSectionNumber)
The formatting's off, as the board doesn't replicate it but, as you'll can see if you do the same, the Data Type is WdInformation. So, I copied that to the Search box and pressed Enter. Up popped:
Quote:
Search results for WdInformation
--------------------------------------------------------------------------------
WdInformation Enumeration
Article
Selection.Information Property
Article
Range.Information Property
Article
So I clicked on the first one and up popped the WdInformation Enumeration:
Quote:
Word 2010 Developer Reference > Word Object Model Reference > Enumerations
Word Developer ReferenceWdInformation Enumeration
Specifies the type of information returned about a specified selection or range.
Name Value Description
wdActiveEndAdjustedPageNumber 1 Returns the number of the page that contains the active end of the specified selection or range. If you set a starting page number or make other manual adjustments, returns the adjusted page number (unlike wdActiveEndPageNumber).

wdActiveEndPageNumber 3 Returns the number of the page that contains the active end of the specified selection or range, counting from the beginning of the document. Any manual adjustments to page numbering are disregarded (unlike wdActiveEndAdjustedPageNumber).

wdActiveEndSectionNumber 2 Returns the number of the section that contains the active end of the specified selection or range.

wdAtEndOfRowMarker 31 Returns True if the specified selection or range is at the end-of-row mark in a table.

wdCapsLock 21 Returns True if Caps Lock is in effect.

wdEndOfRangeColumnNumber 17 Returns the table column number that contains the end of the specified selection or range.

wdEndOfRangeRowNumber 14 Returns the table row number that contains the end of the specified selection or range.

wdFirstCharacterColumnNumber 9 Returns the character position of the first character in the specified selection or range. If the selection or range is collapsed, the character number immediately to the right of the range or selection is returned (this is the same as the character column number displayed in the status bar after "Col").

wdFirstCharacterLineNumber 10 Returns the character position of the first character in the specified selection or range. If the selection or range is collapsed, the character number immediately to the right of the range or selection is returned (this is the same as the character line number displayed in the status bar after "Ln").

wdFrameIsSelected 11 Returns True if the selection or range is an entire frame or text box.

wdHeaderFooterType 33 Returns a value that indicates the type of header or footer that contains the specified selection or range. See the table in the remarks section for additional information.

wdHorizontalPositionRelativeToPage 5 Returns the horizontal position of the specified selection or range; this is the distance from the left edge of the selection or range to the left edge of the page measured in points (1 point = 20 twips, 72 points = 1 inch). If the selection or range isn't within the screen area, returns –1.

wdHorizontalPositionRelativeToTextBoundary 7 Returns the horizontal position of the specified selection or range relative to the left edge of the nearest text boundary enclosing it, in points (1 point = 20 twips, 72 points = 1 inch). If the selection or range isn't within the screen area, returns -1.

wdInClipboard 38 For information about this constant, consult the language reference Help included with Microsoft Office Macintosh Edition.

wdInCommentPane 26 Returns True if the specified selection or range is in a comment pane.

wdInEndnote 36 Returns True if the specified selection or range is in an endnote area in print layout view or in the endnote pane in normal view.

wdInFootnote 35 Returns True if the specified selection or range is in a footnote area in print layout view or in the footnote pane in normal view.

wdInFootnoteEndnotePane 25 Returns True if the specified selection or range is in the footnote or endnote pane in normal view or in a footnote or endnote area in print layout view. For more information, see the descriptions of wdInFootnoteand wdInEndnotein the preceding paragraphs.

wdInHeaderFooter 28 Returns True if the selection or range is in the header or footer pane or in a header or footer in print layout view.

wdInMasterDocument 34 Returns True if the selection or range is in a master document (that is, a document that contains at least one subdocument).

wdInWordMail 37 Returns True if the selection or range is in the header or footer pane or in a header or footer in print layout view.

wdMaximumNumberOfColumns 18 Returns the greatest number of table columns within any row in the selection or range.

wdMaximumNumberOfRows 15 Returns the greatest number of table rows within the table in the specified selection or range.

wdNumberOfPagesInDocument 4 Returns the number of pages in the document associated with the selection or range.

wdNumLock 22 Returns True if Num Lock is in effect.

wdOverType 23 Returns True if Overtype mode is in effect. The Overtype property can be used to change the state of the Overtype mode.

wdReferenceOfType 32 Returns a value that indicates where the selection is in relation to a footnote, endnote, or comment reference, as shown in the table in the remarks section.

wdRevisionMarking 24 Returns True if change tracking is in effect.

wdSelectionMode 20 Returns a value that indicates the current selection mode, as shown in the following table.

wdStartOfRangeColumnNumber 16 Returns the table column number that contains the beginning of the selection or range.

wdStartOfRangeRowNumber 13 Returns the table row number that contains the beginning of the selection or range.

wdVerticalPositionRelativeToPage 6 Returns the vertical position of the selection or range; this is the distance from the top edge of the selection to the top edge of the page measured in points (1 point = 20 twips, 72 points = 1 inch). If the selection isn't visible in the document window, returns –1.

wdVerticalPositionRelativeToTextBoundary 8 Returns the vertical position of the selection or range relative to the top edge of the nearest text boundary enclosing it, in points (1 point = 20 twips, 72 points = 1 inch). This is useful for determining the position of the insertion point within a frame or table cell. If the selection isn't visible, returns –1.

wdWithInTable 12 Returns True if the selection is in a table.

wdZoomPercentage 19 Returns the current percentage of magnification as set by the Percentage property.

Remarks

Possible values for wdHeaderFooterType are shown in the following table.
Value Type of header or footer
-1 None (the selection or range isn't in a header or footer)
0 (zero) Even page header
1 Odd page header (or the only header, if there aren't odd and even headers)
2 Even page footer
3 Odd page footer (or the only footer, if there aren't odd and even footers)
4 First page header
5 First page footer

Possible values for wdReferenceOfType are shown in the following table.
Value Description
–1 The selection or range includes but isn't limited to a footnote, endnote, or comment reference.
0 (zero) The selection or range isn't before a footnote, endnote, or comment reference.
1 The selection or range is before a footnote reference.
2 The selection or range is before an endnote reference.
3 The selection or range is before a comment reference.

Possible values for wdSelectionMode are shown in the following table.
Value Selection mode
0 (zero) Normal selection
1 Extended selection ("EXT" appears on the status bar)
2 Column selection. ("COL" appears on the status bar)

© 2010 Microsoft Corporation. All rights reserved.
Again, the formatting's off, but you get the general idea.

As you can see, 'Information' can return many details. These all have enumerated constants (which I've applied bold/red type to). With early binding, you can use the constants; with late binding you need to use their enumeration. It's a similar story with 'InsertBreak'.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Other Forums: Access Forums

All times are GMT -7. The time now is 02:56 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft