Solved

Highlight Text

Posted on 2012-04-10
8
313 Views
Last Modified: 2012-04-10
Hello Experts,

I have an .txt file which contains .js contents and open it in word document. I would like to highlight the text which is not present between the double quotes. please find below the sample for this.

    BUTTON_SAVE         : "Save",
    BUTTON_OK           :       "OK",
    BUTTON_CANCEL       :       "Cancel",


Can you please suggest any word macro or .vbs file for this?

Thanks in Advance.
Shail
0
Comment
Question by:ShaileshShinde
  • 4
  • 3
8 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 37826493
It isn't clear exactly what you need to be highlighted. You can't highlight text which isn't present and anyway there are no empty quoted strings in your example.
0
 
LVL 1

Author Comment

by:ShaileshShinde
ID: 37826519
Hello Experts,

I would like to highlight the uppercase words that is [BUTTON_SAVE         :],  [BUTTON_OK           :] and leaving rest untouched...

Thanks,
Shail
0
 
LVL 1

Expert Comment

by:everlast4308
ID: 37826582
If I may offer a (crude?) solution...

Assuming colons are uniquely dividing the content you WANT from the content you DON'T WANT, you can further separate them to facilitate Column-Mode selection:

1) Open your TXT file in Notepad++.
2) Find/Replace (CTRL+H)-- find[:]  replace[:\t\t\t\t\t]
-- Note: You need to specify Search Mode: Extended at the bottom of the Find box.
-- This will separate WANT from DON'T WANT by a large amount of dead space.
3) Turn word-wrap OFF (View menu > Word Wrap (you want it unchecked).
4) Use Column-Mode selection to grab the uppercase terms; either:
-- 4.a) Hold ALT+SHIFT while highlighting with the mouse.
-- 4.b) Hold ALT+SHIFT while using the arrow keys to highlight.
5) Copy and paste to new, or copy/select-all/paste to overwrite in existing file.
6) Finally, if there is any excess tabbing within the result, simply find[\t] replace[]

There are many other ways to manipulate a text file, including scripting (as you alluded to), but this can be done pretty quickly, and in a rather simple "usery" kinda way.  I hope it helps!
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:ShaileshShinde
ID: 37826622
Hello Experts,

This works! However, the other engineers who is going to perform this task has requested for a MACRO or VBScript.

Thanks,
Shail
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 37826718
Try this macro:
Sub HL()
    Dim rng As Range
    Set rng = ActiveDocument.Range
    With rng.Find
        .MatchWildcards = True
        .Text = "(BUTTON_[A-Z ]{1,}):"
        Do While .Execute
            rng.HighlightColorIndex = wdYellow
            rng.Collapse wdCollapseEnd
            rng.End = ActiveDocument.Range.End
        Loop
    End With
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:ShaileshShinde
ID: 37827118
Hello Expert,

can it be possible to remove the hardcoded text BUTTON from the line of code...and use regex instead.

.Text = "(BUTTON_[A-Z ]{1,}):"

The reason for this is we can use this for other file with same patterns but might have something else instead of "BUTTON".  

Thanks,
Shailesh
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 125 total points
ID: 37827161
Word Wildcards act very much like Regex.

We would need to know the rules for what to find. The text "BUTTON_" is quite specific and defines precisely what is to be found.

This string: "[A-Z ]{1,}" will find any string of upper-case characters and spaces. Is the underscore always there and are the letters always upper-case? If so, you could try this:

.Text = "[A-Z]{1,}_[A-Z ]{1,}:"
0
 
LVL 1

Author Closing Comment

by:ShaileshShinde
ID: 37827202
Thanks Experts!
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is a feature provided by MS Word that lets you create an Table of Contents for your Word document automatically. To use this feature for other documents there are two steps involved,   1.  Prepare your document for a table of contents (he…
It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question