# MS Word Identifying Absolute Line Number



## CPGDeveloper (Nov 22, 2011)

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?


----------



## Derek Brown (Nov 24, 2011)

I haven't used Word VBA for a long time, so cannot give you a specific answer to your problem.
However, the following may give you a start:
Get line number:
http://www.vbaexpress.com/kb/getarticle.php?kb_id=59
Word VBA Techniques:
http://www.susandoreydesigns.com/software/WordVBATechniques.pdf
You did not say which version of Office is being used, so there may be changes required to the examples given.


----------



## leumruk (Dec 3, 2011)

Hello.
Try 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.


----------



## Macropod (Dec 5, 2011)

To go to the exact same offset, you could use something like:

```
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
```


----------

