Solved

Highlight Text

Posted on 2012-04-10
8
308 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
A Knowledge Base That Stays Up-to-Date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.

707 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

19 Experts available now in Live!

Get 1:1 Help Now