how to populate substring of text from XML into word

S

sam

Hi,

Here is part of the XML file:

<aux>
<prop name="class">Class No.: 2000</prop>
<prop name="major">Major No.: AC</prop>
<aux/>

I want to populate substring info after ':' into corresponding cell in
the table of Word document.

I write the VBA code like this:

Activedocument.Tables(1).Cell(2, 1).Range.Text =
xmlObj.selectSingleNode("//prop[@name='class']").Text

It populates the whole text 'Class No.: 2000' into specific cell.
However, I only want to populate '2000' into that cell. Do you have any
good methods or suggestions to solve this problem? Thank you!!!


Best Regards

Sam
 
J

Jay Freedman

Hi Sam,

Try this:

Dim tempstring As String
Dim pos As Long

tempstring = _
xmlObj.selectSingleNode("//prop[@name='class']").Text

pos = InStr(tempstring, ":")
If pos > 0 Then
' there is a colon, so take everything after it
' and trim off white space before & after
tempstring = Trim$(Mid$(tempstring, pos + 1))
End If

Activedocument.Tables(1).Cell(2, 1).Range.Text = _
tempstring

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
S

sam

Hi, Jay

It works! Perfect! Thank you!!!

Regards

Sam


Jay said:
Hi Sam,

Try this:

Dim tempstring As String
Dim pos As Long

tempstring = _
xmlObj.selectSingleNode("//prop[@name='class']").Text

pos = InStr(tempstring, ":")
If pos > 0 Then
' there is a colon, so take everything after it
' and trim off white space before & after
tempstring = Trim$(Mid$(tempstring, pos + 1))
End If

Activedocument.Tables(1).Cell(2, 1).Range.Text = _
tempstring

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
Hi,

Here is part of the XML file:

<aux>
<prop name="class">Class No.: 2000</prop>
<prop name="major">Major No.: AC</prop>
<aux/>

I want to populate substring info after ':' into corresponding cell in
the table of Word document.

I write the VBA code like this:

Activedocument.Tables(1).Cell(2, 1).Range.Text =
xmlObj.selectSingleNode("//prop[@name='class']").Text

It populates the whole text 'Class No.: 2000' into specific cell.
However, I only want to populate '2000' into that cell. Do you have
any good methods or suggestions to solve this problem? Thank you!!!


Best Regards

Sam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top