MS Word Identifying Absolute Line Number

CPGDeveloper

Board Regular
Joined
Oct 8, 2008
Messages
190
I have an MS Word application where I essentially have two copies of the same document open. At the click of a button I need to go from one document to another, but I need the button to take me to the exact same place in the other document.

I was thinking that identifying line number would be a good way to do it...identify the line number of the document that's active, switch to the other document, and then go to that line number.

I'm having a hell of a time identifying the absolute line number in an ms word doc. You'd think there'd be something built in as there's a Find>Go To Function that allows you to go to a particular line number.

Any ideas?
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Upvote 0
Hello.
Try code.
Code:
Sub dene2()
lrow = Selection.Information(wdFirstCharacterLineNumber)
For Each ldoc In Documents
MsgBox "Flying to the other file.", vbInformation, "Coder: l e u m r u k"
If ldoc.Name <> ActiveDocument.Name Then
ldoc.Activate
  Selection.GoTo What:=wdGoToLine, Which:=wdGoToFirst, Count:=lrow
End If
Exit Sub
Next
End Sub
New learning English. If you pardon the fault.
 
Upvote 0
To go to the exact same offset, you could use something like:
Code:
Sub Switch()
Dim RngStart As Long, RngEnd As Long
RngStart = ActiveDocument.Range(0, Selection.Start).Characters.Count
RngEnd = ActiveDocument.Range(0, Selection.End).Characters.Count
ActiveWindow.Next.Activate
ActiveDocument.Range(RngStart, RngEnd).Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,225,609
Messages
6,185,980
Members
453,333
Latest member
BioCoder84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top