|
-
Jan 18th, 2007, 08:17 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Word: End of Document
In Word, how to check whether the current cursor position is at the end of the document.
Basically, using a loop, I am traversing all the characters of the document with .Selection.MoveRight method. I want to exit the loop when the .Selection is at the end of the document.
Pls guide
-
Jan 18th, 2007, 02:02 PM
#2
Re: Word: End of Document
A new, blank Word document contains a single empty paragraph, which is to say, a single character that happens to be a paragraph mark. Initially, the paragraph mark character has a Start property of 0, because zero items are situated to the left of it, and an End property of 1, because one item is situated to the left of it, counting itself.
When an item in a Word document is selected, Word's Selection object takes on the Start and End properties of that Item. If multiple items are selected, the Selection object takes on the Start property of the first item and the End property of the last item. For example, if the entire contents of a Word document are selected, the Selection object takes on the Start property of the first character in the document and the End property of the final paragraph mark.
The following code takes advantage of this to determine whether the selection includes the document's final paragraph mark.
VB Code:
' Determine whether selection includes final paragraph mark
Dim SelectionIncludesFinalParagraphMark As Boolean
If Selection.Type = wdSelectionNormal _
And Selection.End = ActiveDocument.Content.End _
Then
SelectionIncludesFinalParagraphMark = True
When Word's Insertion Point is flashing in a document, the Selection object's Start and End properties are equal to each other and represent how many items are to the left of the Insertion Point. Since the Insertion Point can travel up to but never past the final paragraph mark in a document, the Start and End properties of the Selection object will never get higher than the Start value of the final paragraph mark, which is to say, one less than the End property of the final paragraph mark.
The following code takes advantage of this to determine whether the insertion point is flashing in front of the document's final paragraph mark.
VB Code:
' Determine whether insertion point is flashing at end of document
Dim InsertionPointFlashingAtEndOfDoc As Boolean
If Selection.Type = wdSelectionIP _
And Selection.End = ActiveDocument.Content.End - 1 _
Then
InsertionPointFlashingAtEndOfDoc = True
Hope this helps...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jan 19th, 2007, 12:50 AM
#3
Junior Member
Re: Word: End of Document
The below coding is help you and it is very easy method
Dim cursor_pos As Long
Dim doc_end As Long
cursor_pos = Selection.Start
doc_end = ActiveDocument.Range.End
doc_end = doc_end - 1
If cursor_pos = doc_end Then
MsgBox "Cursor position is at end of the document"
End If
Thanks,
nit22
-
Feb 5th, 2007, 10:47 AM
#4
Thread Starter
Fanatic Member
Re: Word: End of Document
thx sid....that was very useful....can u tell me how to loop thru all the paragraphs in the document???
basically i want to delete all paragraphs, which starts with specific keywords
thx in advance
Last edited by pvbangera; Feb 5th, 2007 at 10:51 AM.
Microsoft Techie
-
Feb 5th, 2007, 12:46 PM
#5
Re: Word: End of Document
Does this help?
VB Code:
Private Sub CommandButton1_Click()
Dim para As Paragraph
Dim myword As Words
For Each para In ActiveDocument.Paragraphs
'1 for the first word
' 9 because pvbangera has 9 characters
If Left(para.Range.Words(1), 9) = "pvbangera" Then
'Delete Para
para.Range.Delete
End If
Next para
End Sub
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Feb 6th, 2007, 06:06 AM
#6
Thread Starter
Fanatic Member
Re: Word: End of Document
thx again dude...it works...i will bother u once again if i need ur help.
btw, can u tell me how to remove page breaks frm the active document???
regards
-
Feb 6th, 2007, 02:30 PM
#7
Re: Word: End of Document
i will bother u once again if i need ur help.
Anytime If I am not here then there are plenty of members who will...
btw, can u tell me how to remove page breaks frm the active document???
Hi Does this help?
VB Code:
Private Sub CommandButton1_Click()
Dim PVB_Brk As Long ' kind of break
Dim PVBangera As Range ' the documents range
Set PVBangera = ActiveDocument.Range
With PVBangera.Find
.Text = Chr(12)
While .Execute
PVBangera.Select ' Selectin the range
PVB_Brk = Type_Of_Break(PVBangera)
Select Case PVB_Brk
Case -1 '-1 is for page break
'Deleting page Break
Selection.Delete
End Select
PVBangera.Collapse Direction:=wdCollapseEnd
Wend
End With
End Sub
Put this in a module...
VB Code:
Public Function Type_Of_Break(ByVal PVB_Range As Range) As Long
Dim PVB1 As Long ' flag for sections
Dim PVB2 As Long ' flag for sections
PVB_Range.Start = ActiveDocument.Range.Start
PVB1 = PVB_Range.Sections.Count ' count sections
PVB_Range.End = PVB_Range.End + 1 ' extend range
PVB2 = PVB_Range.Sections.Count ' counting sections again
If PVB1 = PVB2 Then ' next character is in the same section
Type_Of_Break = -1 ' ordinary pagebreak
Else
Type_Of_Break = ActiveDocument.Sections(PVB2).PageSetup.SectionStart
End If
End Function
Last edited by Siddharth Rout; Feb 6th, 2007 at 03:40 PM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Feb 6th, 2007, 02:35 PM
#8
Re: Word: End of Document
Also this is the value for different 'selection breaks type' ... (in case you require)
Continuous => 0
NewPage => 2
EvenPage => 3
OddPage => 4
Hope this helps...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Feb 7th, 2007, 03:34 AM
#9
Junior Member
Re: Word: End of Document
The below code helps to remove the page beaks in the activedocument
Dim myrange As Range
Set myrange = ActiveDocument.Range
myrange.Find.ClearFormatting
myrange.Find.Replacement.ClearFormatting
myrange.Find.Execute findtext:="^m", replacewith:="", Replace:=wdReplaceAll, Forward:=True, MatchWildcards:=False
Thanks,
nit22
-
Feb 7th, 2007, 05:27 AM
#10
Thread Starter
Fanatic Member
Re: Word: End of Document
awesome...u ppl are really awesome
vbforum rocks
thx to all
-
Feb 7th, 2007, 05:36 AM
#11
Re: [RESOLVED] Word: End of Document
Glad to be of help 
It really is an amazin forum.....
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Feb 7th, 2007, 05:42 AM
#12
Junior Member
Re: [RESOLVED] Word: End of Document
Last edited by nit22; Feb 7th, 2007 at 05:49 AM.
-
Feb 7th, 2007, 05:45 AM
#13
Re: [RESOLVED] Word: End of Document
@:Nit22: It is absolutely at the Thread owner's discretion. We cannot just ask anyone to rate the post. It seems pretty rude...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Feb 7th, 2007, 05:47 AM
#14
Junior Member
Re: [RESOLVED] Word: End of Document
Ok koolsid. I am new one, sorry I don't know about this.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|