Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2005

Tip: Looking for answers? Try searching our database.

Find & copy macro--possible?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Carrie Downes - 02 Feb 2005 17:49 GMT
I'm wondering if it's possible to create a macro that will search a word
document for any foreign characters with diacritics, copy them, and export
them to a new document? I don't want to remove the characters from where they
are in the text--I just need to know WHICH characters are being used in a
given text. In other words, I need to figure out a thorough way to search
long documents and note any characters that have accents (acute or grave),
breves, umlauts, macrons, etc. Then I need to be able to see a list of the
results so that I know which diacritics are used. Is this even possible?
Dave Lett - 02 Feb 2005 18:51 GMT
Hi Carrie,

From the VBA help file topic "Character Set (128-255), I'm gathering that
you need the characters in the range of 192-255 (generally speaking).
Therefore, if I find any of those characters, I should have found what
you're looking for. Therefore, the following might be what you're looking
for:

Dim iChar As Integer
Dim sFound as String
Dim oDoc As Document
Selection.HomeKey Unit:=wdStory
For iChar = 192 To 255
   With Selection.Find
       .ClearFormatting
       .Text = Chr(iChar)
       .MatchCase = True
       If .Execute Then
           Selection.HomeKey Unit:=wdStory
           sFound = sFound & Chr(iChar) & vbCrLf
       End If
   End With
Next iChar
Set oDoc = Documents.Add
oDoc.Range.InsertAfter Text:=sFound

HTH,
Dave

> I'm wondering if it's possible to create a macro that will search a word
> document for any foreign characters with diacritics, copy them, and export
[quoted text clipped - 4 lines]
> breves, umlauts, macrons, etc. Then I need to be able to see a list of the
> results so that I know which diacritics are used. Is this even possible?
Larry - 02 Feb 2005 19:34 GMT
That's a neat macro.

Larry
Carrie Downes - 02 Feb 2005 19:37 GMT
YAY! That's exactly what I needed. Thanks for your help on this, Dave! You
have no idea how much easier you've just made things for me. Much appreciated!

~Carrie

> Hi Carrie,
>
[quoted text clipped - 34 lines]
> > breves, umlauts, macrons, etc. Then I need to be able to see a list of the
> > results so that I know which diacritics are used. Is this even possible?
Dave Lett - 02 Feb 2005 20:10 GMT
Thanks, Larry, and you're more than welcome, Carrie.

Dave

> YAY! That's exactly what I needed. Thanks for your help on this, Dave! You
> have no idea how much easier you've just made things for me. Much appreciated!
[quoted text clipped - 39 lines]
> > > breves, umlauts, macrons, etc. Then I need to be able to see a list of the
> > > results so that I know which diacritics are used. Is this even possible?
Carrie Downes - 09 Feb 2005 19:13 GMT
Dave,

Is this macro easily adaptable to finding other text within a document and
pulling it out into another separate document? Which line would I change if I
want to modify it for a related function?

Thanks,
~Carrie

> Thanks, Larry, and you're more than welcome, Carrie.
>
[quoted text clipped - 57 lines]
> > > > results so that I know which diacritics are used. Is this even
> possible?
Dave Lett - 09 Feb 2005 19:35 GMT
Hi Carrie,

Well, it depends on what you mean by "other text". If you are looking for
just a word, then we'll have to modify more than one line, and if you're
looking for specific characters, then it _could_ be done by modifying a
single line of code (this assumes the easiest change that might be looking
for).

Perhaps you could describe how you need it to work now?

HTH,
Dave

> Dave,
>
[quoted text clipped - 66 lines]
> > > > > results so that I know which diacritics are used. Is this even
> > possible?
Carrie Downes - 09 Feb 2005 19:57 GMT
I need to search for anything in brackets and then list those in a separate
document, just the same as the diacritics. In other words, I want to search
for any string of characters enclosed in <>. Does this pose a problem because
I need to literally search for text AND the brackets themselves?

> Hi Carrie,
>
[quoted text clipped - 90 lines]
> > > > > > results so that I know which diacritics are used. Is this even
> > > possible?
Dave Lett - 09 Feb 2005 20:29 GMT
Hi Carrie,

That will require an entirely different routine.

Dim sBraces As String
Dim oDoc As Document
With Selection
   .HomeKey Unit:=wdStory
   With .Find
       .ClearFormatting
       .Text = "\<*\>"
       .MatchWildcards = True
       Do While .Execute
           sBraces = sBraces & Selection.Text & vbCrLf
       Loop
   End With
End With

Set oDoc = Documents.Add
oDoc.Range.InsertAfter sBraces
oDoc.Range.Sort

Then, you can use the routine from the article "Delete any paragraph that is
an exact duplicate of the preceding paragraph, using a Selection object" at
http://word.mvps.org/faqs/macrosvba/DeleteParaSel.htm

HTH,
Dave

> I need to search for anything in brackets and then list those in a separate
> document, just the same as the diacritics. In other words, I want to search
[quoted text clipped - 95 lines]
> > > > > > > results so that I know which diacritics are used. Is this even
> > > > possible?
Carrie Downes - 09 Feb 2005 21:25 GMT
That worked perfectly! Although I don't see why I'd need to use the routine
for selecting and deleting duplicate paragraphs that you mentioned at the end
of your posting. I really just needed to be able to identify what's in
brackets in a document. These are typesetting codes that I use as an editor
to prepare a document for a compositor, and I need to be sure that I've
listed all those used.

Thanks again. You've been a tremendous help!  ~Carrie

> Hi Carrie,
>
[quoted text clipped - 32 lines]
> because
> > I need to literally search for text AND the brackets themselves?
Dave Lett - 10 Feb 2005 13:25 GMT
Hi Carrie,

I suggested the second routine so that you would end up with a _unique_ set
of words that we in brackets, just as the first routine only showed one
instance of each character with diacritics. Sounds like you don't really
need it though.

Dave

> That worked perfectly! Although I don't see why I'd need to use the routine
> for selecting and deleting duplicate paragraphs that you mentioned at the end
[quoted text clipped - 41 lines]
> > because
> > > I need to literally search for text AND the brackets themselves?
Carrie Downes - 10 Feb 2005 15:21 GMT
Hi Dave,

Actually...I think it may be better this way. Since this macro shows every
occurrence (and groups them together, no less!), it serves an extra
function--it allows me to check those codes that need to occur in pairs. Many
of our typesetting codes are similar to HTML in that they need opening and
closing codes. So by running the macro, not only can I see that <CA> is used
(meaning chapter author), but also that there is a corresponding </CA> to
close it. This helps tremendously because I can make sure that there aren't
any stray open codes left without a closing code. So thanks!

However, if I did want to modify the first routine (for identifying the
diacritics used) and wanted to do the same for identifying the bracket codes
used (without listing every instance), I'm just curious--how would you do it?
It is possible to modify the first macro?

> Hi Carrie,
>
[quoted text clipped - 58 lines]
> > > because
> > > > I need to literally search for text AND the brackets themselves?
Dave Lett - 10 Feb 2005 15:47 GMT
Hi Carrie,

You _could_ modify the first routine to do something similar. However, it's
more work than it's worth. That is, you'd have to define each unique set of
brackets that you wanted to find and place them in an array. Then you would
cycle through the array, finding each instance (or not finding it).

Dim aBraces
Dim iBraces As Integer
Dim sFound As String
Dim oDoc As Document

aBraces = Array("<brace1>", "<brace2>", "<brace3>") '''and so on

Selection.HomeKey Unit:=wdStory
For iBraces = 0 To UBound(aBraces)
   With Selection.Find
       .ClearFormatting
       .Text = aBraces(iBraces)
       .MatchCase = True
       If .Execute Then
           Selection.HomeKey Unit:=wdStory
           sFound = sFound & Chr(iChar) & vbCrLf
       End If
   End With
Next iBraces
Set oDoc = Documents.Add
oDoc.Range.InsertAfter Text:=sFound

I haven't tested this. I just wrote it up to show that it'd really be less
efficient. For example, it wouldn't find typos in your mark up because you
have to specify exactly which braces to look for, instead of having Word
return all that are in the document.

HTH,
Dave

> Hi Dave,
>
[quoted text clipped - 74 lines]
> > > > because
> > > > > I need to literally search for text AND the brackets themselves?
Carrie Downes - 10 Feb 2005 16:01 GMT
I see. Thanks again for all your help, Dave! I appreciate it.  ~Carrie

> Hi Carrie,
>
[quoted text clipped - 125 lines]
> > > > > because
> > > > > > I need to literally search for text AND the brackets themselves?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.