Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Applications / Word / November 2005



Tip: Looking for answers? Try searching our database.

Find/Replace, with case change

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bella Jones - 25 Nov 2005 16:39 GMT
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

Signature

bellajonez at yahoo dot co dot uk

matt neuburg - 25 Nov 2005 17:44 GMT
> Hi
>
[quoted text clipped - 9 lines]
> 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.

Signature

matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/exec/obidos/ASIN/0596005571
Read TidBITS! It's free and smart. http://www.tidbits.com

Paul Berkowitz - 25 Nov 2005 19:04 GMT
On 11/25/05 9:44 AM, in article 1h6ksqt.1ysakja1in8cgoN%matt@tidbits.com,

>> Hi
>>
[quoted text clipped - 28 lines]
> 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.

Signature

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.

Bella Jones - 26 Nov 2005 07:59 GMT
> On 11/25/05 9:44 AM, in article 1h6ksqt.1ysakja1in8cgoN%matt@tidbits.com,

> >> 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:
> >
[quoted text clipped - 3 lines]
> > 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
[quoted text clipped - 3 lines]
> 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
[quoted text clipped - 7 lines]
> 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.

Signature

bellajonez at yahoo dot co dot uk

Bella Jones - 26 Nov 2005 07:59 GMT
[...]
> > 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
[quoted text clipped - 16 lines]
>   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.

Signature

bellajonez at yahoo dot co dot uk

Daiya Mitchell - 26 Nov 2005 16:06 GMT
>> tell application "Microsoft Word"
>>   tell selection
[quoted text clipped - 5 lines]
> 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.

Signature

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: http://mvp.support.microsoft.com/

Paul Berkowitz - 26 Nov 2005 17:14 GMT
On 11/26/05 8:06 AM, in article BFADC804.5364E%daiyaNOSPAM@mvps.org.INVALID,

> That's actually an AppleScript, rather than a Visual Basic macro.  Here's a
> page that tells you how to use it:
[quoted text clipped - 5 lines]
> 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.

Signature

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.

Daiya Mitchell - 26 Nov 2005 19:28 GMT
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.

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

Daiya

> On 11/26/05 8:06 AM, in article BFADC804.5364E%daiyaNOSPAM@mvps.org.INVALID,
>
[quoted text clipped - 37 lines]
> extension won't display in the menu, but there may be some things in the
> menu behavior that require the extension.

Signature

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: http://mvp.support.microsoft.com/

Paul Berkowitz - 26 Nov 2005 21:53 GMT
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.

Signature

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 <daiyaNOSPAM@mvps.org.INVALID>
> Newsgroups: microsoft.public.mac.office.word
[quoted text clipped - 54 lines]
>> extension won't display in the menu, but there may be some things in the
>> menu behavior that require the extension.
Daiya Mitchell - 28 Nov 2005 05:34 GMT
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

> 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
[quoted text clipped - 4 lines]
> launch) rather than as a .scpt - I'm not sure. I think at least one of them
> can run .scpt files.
Paul Berkowitz - 28 Nov 2005 18:16 GMT
On 11/27/05 9:34 PM, in article BFAFD6C8.53962%daiyaNOSPAM@mvps.org.INVALID,

> 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.)

Signature

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.

Bella Jones - 26 Nov 2005 18:34 GMT
> >> tell application "Microsoft Word"
> >>   tell selection
[quoted text clipped - 14 lines]
>
> 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.

Signature

bellajonez at yahoo dot co dot uk

Matt Centurión [MSFT] - 28 Nov 2005 17:23 GMT
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

Signature

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" <matt@tidbits.com>

>
>> Hi
[quoted text clipped - 29 lines]
> find-and-transform globally, but I'd rather not because you might hit a
> false positive; better to do them one by one. m.
matt neuburg - 28 Nov 2005 18:30 GMT
> Try the following based on the terrific start Matt gave:
>
[quoted text clipped - 12 lines]
>
> 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.

Signature

matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/exec/obidos/ASIN/0596005571
Read TidBITS! It's free and smart. http://www.tidbits.com

 
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.