Click here to Skip to main content
13,092,862 members (72,443 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I am processing 270 books of poetry in word documents in 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 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:

            Dim rng As Word.Range = docWord.Range()
            Dim fnd As Word.Find = rng.Find
            ' Clear existing formatting.
            ' Execute the search
            fnd.Text = "^t"

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

Thanks very much
Posted 19-Oct-11 10:37am
Updated 19-Oct-11 10:40am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try using vbTabs[^].
Dhruva Hein 20-Oct-11 7:29am
Thanks, Andre. Unfortunately, vbTab doesn't work any better than ControlChars.Tab.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Take a look at this code (from MS Word):
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 
    .Text = "^t"
    .MatchWildcards = True
    .Forward = True
    Do While .Execute()
        Set fnd = rng.Find.Parent
        fnd.Underline = wdUnderlineDouble 'underline tab range
End With
    On Error Resume Next
    Set fnd = Nothing
    Set rng = Nothing
    Set doc = Nothing
    Exit Sub
    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:
wrdApp = CreateObject("Word.Application")

To change wdUnderline constant to its value, see here

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 20 Oct 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100