Solved

Highlight Text

Posted on 2012-04-10
8
315 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
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…

691 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