PDA

View Full Version : Any MS Word Macro experts here? I need some help



proud gonzo
8/26/2011, 09:33 AM
Ok, is there a way to write a macro to search for non-black text? I've been trying, but I don't understand programming stuff so much...and that makes it tough. I figured out how to write all the other macros I need, but I'm definitely missing something. Help??


I've gotta edit a 100,000 word manuscript (350 pages) and the woman didn't follow directions with her edits, so I can't just search for red text like normal. And I really don't feel like skanning all 350 pages to find the slightly-reddish text each time she made one of her incorrect changes. So I desperately need help with this. TIA

soonerboomer93
8/26/2011, 10:19 AM
lmbify

http://word.tips.net/T001387_Searching_for_Non-Black_Text.html


p.s. did you read the new dresden yet?

proud gonzo
8/26/2011, 10:39 AM
no, not yet. I haven't had time to read anything but work junk pretty much since I started this job in January... which sucks. I'm actually using Harry Dresden as an example for one of my authors this month. I was flipping through the very first Dresden book lamenting how I couldn't afford to sit there and read something for fun. :( frustrating.


yeah...I tried that macro yesterday, but there's something wrong with it. It crashed my microsoft word and deleted all of my macros... I just spend the past two hours rewriting/recording all of my macros. Anybody know what's wrong with this?

Sub FindNotBlack()
With Selection.Find
.ClearFormatting
.Text = InputBox(prompt:="Enter the search text.", _
Title:="Find Nonblack Text")
Do While .Execute
With Selection.Font
If (.Color <> wdColorAutomatic) And _
(.Color <> wdColorBlack) Then
MsgBox "Found"
Exit Sub
End If
End With
Loop
End With
End Sub

proud gonzo
8/26/2011, 10:40 AM
Also, it says it will prompt with: "Enter the search text:"
what the hell do I do with that?

jkm, the stolen pifwafwi
8/26/2011, 02:44 PM
Try this

Sub FindNotBlack()
Dim X As Integer
For X = 1 To Me.Paragraphs.Count

Me.Paragraphs(X).Range.Find.ClearFormatting

If Me.Paragraphs(X).Range.Find.Font.Color <> wdColorAutomatic Or wdColorBlack Then
Me.Paragraphs(X).Range.Select
MsgBox ("You Got Derp")
End If
X = X + 1
Next
End Sub

jkm, the stolen pifwafwi
8/26/2011, 02:44 PM
That is the input box you have going on. Input boxes expect input ;-)

soonerboomer93
8/26/2011, 02:59 PM
Don't ask me, I just found that one on bing, I don't use word macros.

proud gonzo
8/26/2011, 03:20 PM
Try this

Sub FindNotBlack()
Dim X As Integer
For X = 1 To Me.Paragraphs.Count

Me.Paragraphs(X).Range.Find.ClearFormatting

If Me.Paragraphs(X).Range.Find.Font.Color <> wdColorAutomatic Or wdColorBlack Then
Me.Paragraphs(X).Range.Select
MsgBox ("You Got Derp")
End If
X = X + 1
Next
End Sub
Compile Error:
Invalid use of Me Keyword

That is the input box you have going on. Input boxes expect input ;-)

yeah, but what would I put in the input box? That's what I don't understand. I want it to search and find within my document, just like the search/find function in microsoft word. I can search for a specific color, but I want to search for anything that's NOT black. I still can't get it right.

jkm, the stolen pifwafwi
8/26/2011, 03:36 PM
what version of word are you using?

proud gonzo
8/26/2011, 03:40 PM
Word 2007

jkm, the stolen pifwafwi
8/26/2011, 04:36 PM
that is what i'm using. should be able to step through it (f8) on the vba side and see if its picking up your current doc as "me"

pphilfran
8/26/2011, 05:31 PM
This should highlight them in bright yellow....

Sub HighlightNotBlack()
Dim char As Range

For Each char In ActiveDocument.Characters
If char.Font.Color <> wdColorAutomatic And char.Font.Color <> wdColorBlack Then
char.HighlightColorIndex = wdYellow
End If
Next
End Sub

Penguin
8/26/2011, 06:51 PM
So, you have a macro that just looks for red? Just load that up and change "if text = red" to "if text != black and text != default". I don't know VBA, so I can't tell you the exact syntax.


If you post your "find red text" macro, I'm sure I could make an educated guess.

proud gonzo
8/27/2011, 12:17 AM
that is what i'm using. should be able to step through it (f8) on the vba side and see if its picking up your current doc as "me"
I don't know what that means...

This should highlight them in bright yellow....

Sub HighlightNotBlack()
Dim char As Range

For Each char In ActiveDocument.Characters
If char.Font.Color <> wdColorAutomatic And char.Font.Color <> wdColorBlack Then
char.HighlightColorIndex = wdYellow
End If
Next
End Sub
Okay, that works. Then I should be able to use my macro to find yellow highlight and my other macros for changing text color and stripping highlight to fix it all. More steps than i hoped for, but still quicker than searching the damn thing line by line. thanks!

So, you have a macro that just looks for red? Just load that up and change "if text = red" to "if text != black and text != default". I don't know VBA, so I can't tell you the exact syntax.


If you post your "find red text" macro, I'm sure I could make an educated guess.
Here's the find red macro--i think i just used the record macro setting for this one, so I don't know what most of it means. I've tried the exclamation point thing, but that just results in error messages too.

Sub FindRedText()
'
' FindRedText Macro
'
'
Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorRed
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
End Sub

Penguin
8/27/2011, 01:24 PM
Well, it looks like Microsoft is not going to allow me to do what I was hoping to do. I tinkered around with it for a while, but I just can't get it to do what you want it to do. I gave it the old college try, but I am defeated.

I don't really know Visual Basic, but there has got to be a way to "get" the font color of the selection and check it against black/automatic. Continue to next char if true, stop if not. There's bound to be someone on here that can do it.

jkm, the stolen pifwafwi
8/27/2011, 08:23 PM
You don't have to have a macro to find them. Once its in one color, you just pull up the Find window (CNTL-F), click more>>, click the font button at the bottom, click the color you made them on the font color pallet, click okay and it will just take you to them.

StoopTroup
8/27/2011, 08:47 PM
You should clean out your PM box. The Wife might be able to help you.

Nevermind....she said JKM is right on the money.

proud gonzo
8/27/2011, 09:30 PM
You don't have to have a macro to find them. Once its in one color, you just pull up the Find window (CNTL-F), click more>>, click the font button at the bottom, click the color you made them on the font color pallet, click okay and it will just take you to them. That finds any highlight color, not just the one you specified.

proud gonzo
8/27/2011, 09:31 PM
You should clean out your PM box. The Wife might be able to help you.

Nevermind....she said JKM is right on the money. Dude, I don't even know how to find the PM box on this new site.

StoopTroup
8/27/2011, 09:36 PM
Email sent