Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-07-2013, 02:10 PM
Designergrrl Designergrrl is offline Replace Unless Style = Hyperlink? Mac OS X Replace Unless Style = Hyperlink? Office for Mac 2011
Novice
Replace Unless Style = Hyperlink?
 
Join Date: Oct 2013
Posts: 5
Designergrrl is on a distinguished road
Default Replace Unless Style = Hyperlink?

Hi all and thanks in advance for any replies;



This question is about replacing text only under certain conditions.

Background: I'm working on a macro for the editorial department of an academic institution. They get loads of documents that have the same issues and asked for some help to reduce the time they spend on each one.

Two of the things they want:
  • If a hyphen is between two digits, change it to an en-dash
  • Change every ampersand (&) to the word "and"
I have a RegExp that finds and replaces those hyphens, but I noticed a problem. My find/replace changes the "display text" of hyperlinks. Same with ampersands. Bad. So what I'm trying to figure out is how to exclude text that has Selection.Style = Word.ActiveDocument.Styles("Hyperlink")

BTW, what's the logical operator for "not equal"? I tried <> and >< but I always get an error telling me that an expression is expected. I'm new to VBA so please forgive the newbie question.

This is working (part of a much larger Sub):

Code:
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "([0-9])-([0-9])"
        .Replacement.Text = "\1" & Chr$(150) & "\2"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = True
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
So can I create an If/Then statement to tell it to replace only if the style is not hyperlink?

Thanks again,
Rissa
Reply With Quote
 

Tags
conditional, replace



Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace Unless Style = Hyperlink? Insert the Hyperlink and hide all sheets except clicking Hyperlink PRADEEPB270 Excel 1 02-22-2013 09:47 AM
Hyperlink/Data Insert & replace jclinton Word 1 09-19-2012 07:22 PM
Replace Unless Style = Hyperlink? Macro to replace one specific heading style with another ubns Word VBA 44 09-04-2012 08:17 PM
Find bullets and replace with paragraph style? cdybdahl Word 1 12-02-2011 02:14 AM
Find and replace multiple documents change style BaPW Word 0 08-14-2011 11:12 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:19 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft