Re: Making text plain or bold in Word
Re: Making text plain or bold in Word
- Subject: Re: Making text plain or bold in Word
- From: "Oz.Springs" <email@hidden>
- Date: Sat, 12 Apr 2003 07:51:48 +0100
I could not get this script to work at all. Shane's script works partially (tested it out on a 2nd document and it retains centred, underlined text and bold).
The scripts that do work are Paul Berkowitz's and mine ("clunky" as it is).
Oz
At 17:37 +1200 12/04/2003, David Wignall wrote:
>
on 4/12/03 4:56 AM, Frank W. Walker at email@hidden wrote:
>
>
> This is probably simple, but I am pulling my hair out over it.
>
>
>
> All I want to do is change all text in an opened Word document to "plain",
>
> then change the first two words of text to "bold".
>
>
Which on 4/12/03 7:32 AM, prompted Paul Berkowitz at email@hidden to
>
reply, regarding another reply from "Oz.Springs" <email@hidden>:
>
>
> You should not be including the Sub/End Sub when using in 'do Visual Basic'.
>
> And just as in regular AppleScript, you should not use Selection when it's
>
> not necessary - it's clunky and slower. 'Words' in VB can consist just of
>
> tabs or other white space, and should be excluded.
>
>
Why do you feel the need to excluded spaces in this case Paul? The 'Word'
>
object is the equivalent of what you get by double clicking on a word in the
>
interface and AFAIK a space on its own will never be considered as a word.
>
>
> It's possible that Normal style will not be plain text although it is,
>
> virtually always true enough, with the user's default font (usually Times)
>
> which is plain enough, I'm sure. Then you can just set the style to Normal and
>
> - most important - Reset the Font to remove manually applied formatting.
>
>
People do terrible things with Normal and it should not be relied on. In any
>
case, I took the original question to mean that they wanted to remove all
>
typeface styles but not perhaps change the typeface itself. So, I now offer
>
>
tell application "Microsoft Word"
>
do Visual Basic "
>
Dim rngWord As Range
>
Dim i As Integer
>
With ActiveDocument
>
With .Range
>
With .Font
>
.Bold = False
>
.Italic = False
>
.Underline = wdUnderlineNone ' and so forth
>
End With
>
End With
>
For Each rngWord In .Words
>
With rngWord
>
If .Text <> vbTab Then
>
If .Text <> vbNewLine Then
>
rngWord.Font.Bold = True
>
i = i + 1
>
End If
>
End If
>
End With
>
If i = 2 Then Exit For
>
Next rngWord
>
End With
>
"
>
end tell
>
>
although I like Shane Stanley's solution more :)
>
>
> I haven't been able to discover any generic "white space" constant in VBA,
>
> so I check to make sure that a 'word' has at least one character with an
>
> ASCII number higher than 32 (i.. a visible character). When I first tested
>
> this without that check it found all the tabs in my first line as "words" so
>
> the real words never got bolded.
>
>
Nothing for a space but you can use vbTab for the tabs and vbNewline for the
>
paragraph marker. You need to watch out for the cell mark when tables are
>
involved as well.
>
>
> This script is super fast, with no clunky selecting going on:
>
>
I would like to offer a couple of points here, if you don't mind. Um,
>
otherwise stop reading, I guess :)
>
>
> tell application "Microsoft Word"
>
>
>
> do Visual Basic "
>
> Dim myStory As Variant
>
> Dim myWord As Variant, char As Variant
>
> Dim i As Integer, c As Integer, w As Integer
>
>
>
> For Each myStory In ActiveDocument.StoryRanges
>
> myStory.Style = wdStyleNormal
>
> myStory.Font.Reset
>
> Next myStory
>
>
StoryRanges is a collection so you wouldn't ordinarily use the For Each
>
construction but rather 'For i = 1 to 11.' to enumerate each member. This is
>
why the VBE has insisted you dim myStory as a variant
>
>
> i = 0
>
> w = 0
>
>
Did you need to do this in testing? Typically i and w would be set to zero
>
when they were declared.
>
>
> c = ActiveDocument.Words.Count
>
>
Maybe Long for c's data type, rather than an integer, as it doesn't take
>
much to get past 37700-odd words.
>
>
> For Each myWord In ActiveDocument.Words
>
>
Technically, 'myWord' should have been declared as a Range or an Object,
>
rather than a Variant. The same applies to 'char'
>
>
--
>
FWIW
>
Dave
>
_______________________________________________
>
applescript-users mailing list | email@hidden
>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.