-3

please try to specifically answer my question and not offer alternative approaches as I have a very specific problem that needs this ad-hoc solution. Thank you very much.

Automatically my code opens Word through VB.NET, opens the document, finds the table, goes to a cell, moves that cells.range.text into a String variable and in a For loop compares character at position p to a String.

I have tried Strings: "^p", "^013", "U+00B6"

My code:

Dim nextString As String

    'For each cell, extract the cell's text.
    For p = 17 To word_Rng.Cells.Count
        nextString = word_Rng.Cells(p).Range.Text
        'For each text, search for structure.
        For q = 0 To nextString.Length - 1
            If (nextString.Substring(q, 1) = "U+00B6") Then
                Exit For
            End If
        Next
    Next

Is the structural data lost when assigning the cells text to a String variable. I have searched for formatting marks like this in VBA successfully in the past.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Jimbo
  • 3
  • 5
  • Seems VB.NET Strings do not include the character reference '00B6', hence no Pilcrow. Is there another data type i can cast the Word.Document.table.cell.range.text to? – Jimbo Jul 31 '15 at 15:33

1 Answers1

0

Assuming that your string contains the character, you can use ChrW to create the appropriate character from the hex value, and check for that:

If nextString.Substring(q, 1) = ChrW(&h00B6) Then
    Exit For
End If

UPDATE

Here's a complete example:

Dim nextString = "This is a test " & ChrW(&H00B6) & " for that char"
Console.WriteLine(nextString)

For q = 0 To nextString.Length - 1
    If nextString(q) = ChrW(&H00B6) Then
        Console.WriteLine("Found it: {0}", q)
    End If
Next

This outputs:

This is a test ¶ for that char
Found it: 15
Mark
  • 8,140
  • 1
  • 14
  • 29
  • I had done as you've now suggested Mark, before i commented on my question. It seems that the '&00B6 cannot be converted to Integer (my interpretation is that it is not included in the conversion table), and so the Pilcrow doesn't exist. – Jimbo Jul 31 '15 at 19:22
  • @Jimbo Not sure what you mean by "It seems that the '&00B6 cannot be converted to Integer", but make sure you are using &H00B6 - no quotes, and note the H - this is a hex constant. – Mark Jul 31 '15 at 19:36
  • Thank you so much! All that was missing was the 'H', why the hell don't the Microsoft examples (MSDN) include this?! – Jimbo Aug 01 '15 at 16:05