Click here to Skip to main content
15,894,265 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am processing 270 books of poetry in word documents in vb.net using word automation.

One of the problems is locating anomalous lines that have between 5 and 12 tabs at the beginning. These have to be processed separately.

However, when I open one of the documents in vb.net using word automation, I cannot find a way to locate these lines. I have looked for tabs using "^t", ChrW(9) and ControlChars.Tab. I even tried typing a tab on the keyboard between quotes. None of them find the line with all the tabs. Using the same code with "A" or anything similar as a search term works fine.

Here's a snippet of the code:


VB
Dim rng As Word.Range = docWord.Range()

rng.Select()

Dim fnd As Word.Find = rng.Find

' Clear existing formatting.
fnd.ClearFormatting()

' Execute the search
fnd.Text = "^t"

Can anyone help me with why this doesn't work?

Thanks very much
Posted
Updated 19-Oct-11 10:40am
v3

Try using vbTabs[^].
 
Share this answer
 
Comments
Dhruva Hein 20-Oct-11 7:29am    
Thanks, Andre. Unfortunately, vbTab doesn't work any better than ControlChars.Tab.
Take a look at this code (from MS Word):
VB
Option Explicit

Sub FindTabs()

Dim doc As Document
Dim rng As Range, fnd As Range

On Error GoTo Err_FindTabs

Set doc = ActiveDocument 'or Documents(docname) or Documents.Open(FullFilename)
Set rng = doc.Range

With rng.Find 
    .ClearFormatting
    .Text = "^t"
    .MatchWildcards = True
    .Forward = True
    Do While .Execute()
        Set fnd = rng.Find.Parent
        fnd.Underline = wdUnderlineDouble 'underline tab range
    Loop
End With

Exit_FindTabs:
    On Error Resume Next
    Set fnd = Nothing
    Set rng = Nothing
    Set doc = Nothing
    Exit Sub

Err_FindTabs:
    MsgBox Err.Description, vbExclamation, Err.Number
    Resume Exit_FindTabs
End Sub

To use it in Vb.Net, you need to create instance of MS Word Application - like this:
VB
wrdApp = CreateObject("Word.Application")

To change wdUnderline constant to its value, see here
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900