Solved

Highlight Text

Posted on 2012-04-10
8
309 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

929 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now