Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word 2010 need the 657 character in an XML file 1

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I am createing a .NET app which is making an XMl file to import into SQL and need to find an error which is says it at character 657.
I pasted the XML string into Word and thougth there was a way for it to tell me where that character is at?
All it has is a line count and column count. Is there a way to make a macro to find where 657 is in the document?

or any other suggestions?

TIA

DougP
 
I would have thought, "mid()".

_________________
Bob Rashkin
 
I usually do such things with Unicode capable editors such as Notepad++.
These have line numbering, plus it has a "goto character" function. :)

That said, here is a simple Word macro that reproduces this goto character function in a crude fashion. It may not always be 100% accurate though:
Code:
Sub myGoToChar()
Dim numPar As Integer, char2GoTo

    char2GoTo = 651
    Selection.HomeKey unit:=wdStory
    Selection.End = Selection.End + char2GoTo
    'count number of paragraphs to correct range end position
    numPar = Selection.Paragraphs.Count
    Selection.End = Selection.End + numPar - 1
    Selection.Start = Selection.End - 1
    
End Sub

Good luck.


“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
At least until Word 2003 one can display the "Word Count" toolbar, with document/selection counting options.

combo
 
SWEET !!!!
have a STAR, I also created a form so I could just type in a value in a text box and hit a button to find the Character position.

Code:
Private Sub cmdGotoCharacter_Click()
    Dim numPar As Integer, char2GoTo
    char2GoTo =[highlight #FCE94F] Me.txtCharacterNumber.Text[/highlight]   
    Selection.HomeKey unit:=wdStory
    Selection.End = Selection.End + char2GoTo
    'count number of paragraphs to correct range end position
    numPar = Selection.Paragraphs.Count
    Selection.End = Selection.End + numPar - 1
    Selection.Start = Selection.End - 1
End Sub
' module code to laod form
Public Sub LoadfrmFindACharacterPosition()
   Load frmFindACharacterPosition
   frmFindACharacterPosition.Show 0
End Sub

DougP
 
You can get the same result far more simply:
Code:
Sub FindChar()
Dim CharNum As Long, Rng As Range
CharNum = InputBox("Which character # do you want to select?", "Character Finder")
Set Rng = ActiveDocument.Range(0, CharNum)
Rng.End = Rng.End + Rng.Paragraphs.Count - 1
Rng.Characters.Last.Select
End Sub

Cheers
Paul Edstein
[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top