Find/Replace, with case change

B

Bella Jones

Hi

Using Word 2004 here.

I've got a bunch of documents here, and certain names are in CAPS, when
they actually need to be in Title Case and bold. Of course, I could do
it name by name, but for speed I wondered if it was possible to just
find 'Word that is in capitals' and replace that with 'Word that is in
sentence case with bold'.

I have tried and tried, but I can't see a way to do this in
Find/Replace. The only option offered by the Font menu is 'All Caps',
and it's not what I'm after.

Thanks a lot for any pointers.

Bella
 
P

Paul Berkowitz

Bella Jones said:
Hi

Using Word 2004 here.

I've got a bunch of documents here, and certain names are in CAPS, when
they actually need to be in Title Case and bold. Of course, I could do
it name by name, but for speed I wondered if it was possible to just
find 'Word that is in capitals' and replace that with 'Word that is in
sentence case with bold'.

I have tried and tried, but I can't see a way to do this in
Find/Replace. The only option offered by the Font menu is 'All Caps',
and it's not what I'm after.

Use Wildcards checked, and search for:

<[A-Z]{2,}>

There is no "replace" that changes case (it's a true transformation, not
a style), so you will have to apply the case change directly. This
script makes it easy:

tell application "Microsoft Word"
tell selection
set case of text object to title word
set bold of font object to true
end tell
end tell

I could combine those for you into a single script that does the whole
find-and-transform globally, but I'd rather not because you might hit a
false positive; better to do them one by one. m.

Note that in Word 2004, you can have multiple, non-contiguous bits selected
by using the command (Apple) key when making selections. I think you can get
up to 10 selected this way. So you _should_ be able to do that, then run the
script just once (before moving on to further selections, if needed).

However, there appears to be a bug, or rather a necessary limitation*. When
you get the 'text object' of such a multiple-bits-selection, the result is
just the final bit, not all of them. (Get the 'content' of the text object
to verify.) On the other hand, 'font object' actually gets all the bits. So
when you run Matt's script on a multiple-bits-selection, all the bits become
bold, but only the last bit shifts to Title Case. So you'd need to run the
script on each bit separately, each selected one at a time.

*I can see why this might be a necessary limitation: 'text object' is a text
range, defined in the dictionary as "a contiguous area in a document. Each
text range object is defined by a starting and ending character position."
This is not true for a font object - hence the difference in treatment.
'text range' and 'text object of selection' (or rather their VBA precursors)
were defined before multiple-bit-selection was introduced: this type of
selection no longer has a single range. I honestly don't see how you _could_
have a single 'text object' of such a selection. But I think that there
ought to be a simple way to get all the contiguous ranges of the selection
and then act on all of them. Such does not appear to be the case - I'll
report it.

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
B

Bella Jones

matt neuburg said:
I've got a bunch of documents here, and certain names are in CAPS, when
they actually need to be in Title Case and bold. Of course, I could do
it name by name, but for speed I wondered if it was possible to just
find 'Word that is in capitals' and replace that with 'Word that is in
sentence case with bold'.

Use Wildcards checked, and search for:

<[A-Z]{2,}>

There is no "replace" that changes case (it's a true transformation, not
a style), so you will have to apply the case change directly. This
script makes it easy:

tell application "Microsoft Word"
tell selection
set case of text object to title word
set bold of font object to true
end tell
end tell

OK, great, thanks. But what do I do with the script above - make it into
a macro? Not sure how to do this - I'm no Visual Basic user...
I could combine those for you into a single script that does the whole
find-and-transform globally, but I'd rather not because you might hit a
false positive; better to do them one by one. m.

There might well be a few of those, although not many.
 
B

Bella Jones

Paul Berkowitz said:
I've got a bunch of documents here, and certain names are in CAPS, when
they actually need to be in Title Case and bold. Of course, I could do
it name by name, but for speed I wondered if it was possible to just
find 'Word that is in capitals' and replace that with 'Word that is in
sentence case with bold'.
[...]
Use Wildcards checked, and search for:

<[A-Z]{2,}>

There is no "replace" that changes case (it's a true transformation, not
a style), so you will have to apply the case change directly. This
script makes it easy:
[...]

Note that in Word 2004, you can have multiple, non-contiguous bits selected
by using the command (Apple) key when making selections. I think you can get
up to 10 selected this way. So you _should_ be able to do that, then run the
script just once (before moving on to further selections, if needed).
OK...

However, there appears to be a bug, or rather a necessary limitation*. When
you get the 'text object' of such a multiple-bits-selection, the result is
just the final bit, not all of them. (Get the 'content' of the text object
to verify.) On the other hand, 'font object' actually gets all the bits. So
when you run Matt's script on a multiple-bits-selection, all the bits become
bold, but only the last bit shifts to Title Case. So you'd need to run the
script on each bit separately, each selected one at a time.

Ah... So maybe it would be a question of doing all the bold, and then
all the titles.
*I can see why this might be a necessary limitation: 'text object' is a text
range, defined in the dictionary as "a contiguous area in a document. Each
text range object is defined by a starting and ending character position."
This is not true for a font object - hence the difference in treatment.
'text range' and 'text object of selection' (or rather their VBA precursors)
were defined before multiple-bit-selection was introduced: this type of
selection no longer has a single range. I honestly don't see how you _could_
have a single 'text object' of such a selection. But I think that there
ought to be a simple way to get all the contiguous ranges of the selection
and then act on all of them. Such does not appear to be the case - I'll
report it.

Thanks. It's a shame you can't somehow do this simply.
 
D

Daiya Mitchell

tell application "Microsoft Word"
OK, great, thanks. But what do I do with the script above - make it into
a macro? Not sure how to do this - I'm no Visual Basic user...

Hi Bella,

That's actually an AppleScript, rather than a Visual Basic macro. Here's a
page that tells you how to use it:

http://daiya.mvps.org/applescript.htm

You might want to test on a COPY of your document.

I just wrote the page yesterday, and it's a draft, so comments for
improvement welcome.
 
P

Paul Berkowitz

That's actually an AppleScript, rather than a Visual Basic macro. Here's a
page that tells you how to use it:

http://daiya.mvps.org/applescript.htm

You might want to test on a COPY of your document.

I just wrote the page yesterday, and it's a draft, so comments for
improvement welcome.

"5. Save the script in ~/Library/Scripts/. [~ is short for your username or
home folder in OS X]. All scripts saved in ~/Library/Scripts/ are available
from the main script menu in OS X. You can easily categorize your scripts by
creating subfolders in ~/Library/Scripts/ that will be reflected in the
menu."

You may not be aware, Daiya, that if you want certain to appear in the
Script menu only when the application they target is active (in the front),
you should make a folder called "Applications" inside ~/Library/Scripts/.
Then make subfolders named exactly for the applications, e.g. "Microsoft
Word", inside that Applications folder, e.g.:

~/Library/Scripts/Applications/Microsoft Word/

If you put your scripts in there, they will only appear when Word is in the
front. This is great for avoiding clutter in the script menu if you have
scripts for many applications. Don't put scripts that open selected .doc
files there, though: you'd want to have those available when you're in the
Finder, for example.

You also haven't mentioned that scripts destined for the Script menu should
be saved as "script" (i.e. with the Format popup set to "script", not
"application" or "text"), the default: this way they will run immediately,
with no delay. By contrast, scripts saved as application first have to
launch, bouncing in the dock, taking several seconds (but can be launched
outside the menu, by double-clicking them). When you save a script as
"script", Script Editor will add a ".scpt" extension - let it do so: the
extension won't display in the menu, but there may be some things in the
menu behavior that require the extension.

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
B

Bella Jones

Daiya Mitchell said:
Hi Bella,

That's actually an AppleScript, rather than a Visual Basic macro. Here's a
page that tells you how to use it:

http://daiya.mvps.org/applescript.htm

You might want to test on a COPY of your document.

Thanks for all the help. folks. I have now tried the script, but it is
very picky about what it changes, and will only work on one selection at
a time, or, as was suggested, does the last one in a list of separately
highlighted items.

I suspect that for now, doing a find/replace for each name in these
documents (as they are repeated) is going to be quicker.
 
D

Daiya Mitchell

Thanks for the improvements on the page, Paul! You know I don't know much
re AppleScript, but we clearly needed a page to refer people to and google
didn't seem to turn one up. :) And the Entourage one doesn't work for Word.

Fixes made--I had not a clue re the Applications trick. Planning to add a
note re keyboard access in the next couple days.
Daiya



That's actually an AppleScript, rather than a Visual Basic macro. Here's a
page that tells you how to use it:

http://daiya.mvps.org/applescript.htm

You might want to test on a COPY of your document.

I just wrote the page yesterday, and it's a draft, so comments for
improvement welcome.

"5. Save the script in ~/Library/Scripts/. [~ is short for your username or
home folder in OS X]. All scripts saved in ~/Library/Scripts/ are available
from the main script menu in OS X. You can easily categorize your scripts by
creating subfolders in ~/Library/Scripts/ that will be reflected in the
menu."

You may not be aware, Daiya, that if you want certain to appear in the
Script menu only when the application they target is active (in the front),
you should make a folder called "Applications" inside ~/Library/Scripts/.
Then make subfolders named exactly for the applications, e.g. "Microsoft
Word", inside that Applications folder, e.g.:

~/Library/Scripts/Applications/Microsoft Word/

If you put your scripts in there, they will only appear when Word is in the
front. This is great for avoiding clutter in the script menu if you have
scripts for many applications. Don't put scripts that open selected .doc
files there, though: you'd want to have those available when you're in the
Finder, for example.

You also haven't mentioned that scripts destined for the Script menu should
be saved as "script" (i.e. with the Format popup set to "script", not
"application" or "text"), the default: this way they will run immediately,
with no delay. By contrast, scripts saved as application first have to
launch, bouncing in the dock, taking several seconds (but can be launched
outside the menu, by double-clicking them). When you save a script as
"script", Script Editor will add a ".scpt" extension - let it do so: the
extension won't display in the menu, but there may be some things in the
menu behavior that require the extension.
 
P

Paul Berkowitz

Keyboard access for scripts in the system Script menu? In the sense that
"there is none", I trust - that's its biggest lack (especially for people
who know individual script menus such as Entourage's, or the old "OSA menu"
in OS 8/9). I believe that 3rd-party utilities such as QuicKeys, iKey and
DragStuff (none of which is free), do let you run scripts from key combos.
Some of those might require that the script be saved as an .app (slow to
launch) rather than as a .scpt - I'm not sure. I think at least one of them
can run .scpt files.

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.

From: Daiya Mitchell <[email protected]>
Newsgroups: microsoft.public.mac.office.word
Date: Sat, 26 Nov 2005 11:28:24 -0800
Conversation: Find/Replace, with case change
Subject: Re: Find/Replace, with case change

Thanks for the improvements on the page, Paul! You know I don't know much
re AppleScript, but we clearly needed a page to refer people to and google
didn't seem to turn one up. :) And the Entourage one doesn't work for Word.

Fixes made--I had not a clue re the Applications trick. Planning to add a
note re keyboard access in the next couple days.
Daiya



That's actually an AppleScript, rather than a Visual Basic macro. Here's a
page that tells you how to use it:

http://daiya.mvps.org/applescript.htm

You might want to test on a COPY of your document.

I just wrote the page yesterday, and it's a draft, so comments for
improvement welcome.

"5. Save the script in ~/Library/Scripts/. [~ is short for your username or
home folder in OS X]. All scripts saved in ~/Library/Scripts/ are available
from the main script menu in OS X. You can easily categorize your scripts by
creating subfolders in ~/Library/Scripts/ that will be reflected in the
menu."

You may not be aware, Daiya, that if you want certain to appear in the
Script menu only when the application they target is active (in the front),
you should make a folder called "Applications" inside ~/Library/Scripts/.
Then make subfolders named exactly for the applications, e.g. "Microsoft
Word", inside that Applications folder, e.g.:

~/Library/Scripts/Applications/Microsoft Word/

If you put your scripts in there, they will only appear when Word is in the
front. This is great for avoiding clutter in the script menu if you have
scripts for many applications. Don't put scripts that open selected .doc
files there, though: you'd want to have those available when you're in the
Finder, for example.

You also haven't mentioned that scripts destined for the Script menu should
be saved as "script" (i.e. with the Format popup set to "script", not
"application" or "text"), the default: this way they will run immediately,
with no delay. By contrast, scripts saved as application first have to
launch, bouncing in the dock, taking several seconds (but can be launched
outside the menu, by double-clicking them). When you save a script as
"script", Script Editor will add a ".scpt" extension - let it do so: the
extension won't display in the menu, but there may be some things in the
menu behavior that require the extension.

--
Daiya Mitchell, MVP Mac/Word
Word FAQ: http://www.word.mvps.org/
MacWord Tips: <http://www.word.mvps.org/MacWordNew/>
What's an MVP? A volunteer! Read the FAQ:
 
D

Daiya Mitchell

I guess I was remembering the whole "incorporate a keyboard shortcut into
the name of the script" thing. No longer in OS X? And I was blaming
Apple's pathetic Help for not being able to find an explanation of it. :)

Thanks, never mind then. Page more or less finished.
Daiya
 
M

Matt Centurión [MSFT]

Ugh, you guys and your crazy AppleScripts ;)

There's a way to do this in 2 extra steps:
Try the following based on the terrific start Matt gave:

1) Choose "Edit | Find..."
2) Click on the "More" arrow to expose additional options
3) Enable "Use Wildcards"
4) In "Find what" box type:
<[A-Z]{2,}>
5) Click "Highlight all items found in: Main Document"
6) Execute the Find

Now, with all the instances selected:

1) Turn on Bold (once will apply to all selections)
2) Choose "Format | Change Case" and choose "Title Case"

That worked for me. Thanks for the good start Matt!


Matt
MacWord Testing
Microsoft

--
This posting is provided "AS IS" with no warranties, and confers no rights.

MS Mac Newsgroups: http://www.microsoft.com/mac/support/newsgroups.asp
MS Mac News & Updates: http://www.microsoft.com/mac





Date: 11/25/05 9:44 AM / From: "matt neuburg said:
Bella Jones said:
Hi

Using Word 2004 here.

I've got a bunch of documents here, and certain names are in CAPS, when
they actually need to be in Title Case and bold. Of course, I could do
it name by name, but for speed I wondered if it was possible to just
find 'Word that is in capitals' and replace that with 'Word that is in
sentence case with bold'.

I have tried and tried, but I can't see a way to do this in
Find/Replace. The only option offered by the Font menu is 'All Caps',
and it's not what I'm after.

Use Wildcards checked, and search for:

<[A-Z]{2,}>

There is no "replace" that changes case (it's a true transformation, not
a style), so you will have to apply the case change directly. This
script makes it easy:

tell application "Microsoft Word"
tell selection
set case of text object to title word
set bold of font object to true
end tell
end tell

I could combine those for you into a single script that does the whole
find-and-transform globally, but I'd rather not because you might hit a
false positive; better to do them one by one. m.
 
P

Paul Berkowitz

I guess I was remembering the whole "incorporate a keyboard shortcut into
the name of the script" thing. No longer in OS X? And I was blaming
Apple's pathetic Help for not being able to find an explanation of it. :)

It's got nothing to do with OS X - since there never was a system script
menu at all in OS 9 - nor with Apple's Help.

What you're undoubtedly thinking of, Daiya, (the "incorporate a keyboard
shortcut into the name of the script" thing) is the method used by
_Entourage_ in its own proprietary script menu (and explained in the
_Entourage Help_ under "About the Script menu"). Other, non-Microsoft,
applications which have their own script menus sometimes have similar (but
different) methods.

If Word, Excel and PowerPoint also had their own script menus (make you
feature requests here, now) they could incorporate similar methods, or
perhaps Word could include scripts in Tools/Customize/Keyboard as it
currently does for macros. Also, scripts would ruin much faster since they'd
be run by the application itself without having to queue AppleEvents to send
to the application from outside. So, PLEASE, make your feature request here.

Otherwise, if Apple ever creates a similar scheme for its system script menu
(probably a lot easier said than done, what with all the other keystroke
interceptions in place in System Preferences, and especially to incorporate
"application-only" keyboard shortcuts for application-only scripts), we'd be
able to do it there. But, no it doesn't exist, nor did it ever exist in OS
9, since there was no system script menu there. (There was a 3rd-party
utility, which not many people knew about, called OSA Menu, which let you do
this, but had bugs. If I remember correctly, there was one OS package only,
maybe OS 8.5, which included a Lite version of OSA Menu that you could
install if you knew about it.)

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
M

matt neuburg

Matt Centurión said:
Try the following based on the terrific start Matt gave:

1) Choose "Edit | Find..."
2) Click on the "More" arrow to expose additional options
3) Enable "Use Wildcards"
4) In "Find what" box type:
<[A-Z]{2,}>
5) Click "Highlight all items found in: Main Document"
6) Execute the Find

Now, with all the instances selected:

1) Turn on Bold (once will apply to all selections)
2) Choose "Format | Change Case" and choose "Title Case"

That worked for me.

But, as I said in my original post, it's unwise, since you may be
selecting (and altering) false positives. m.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top