Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-10-2012, 03:55 PM
Jack Jack is offline Find and Replace Format macro issue Mac OS X Find and Replace Format macro issue Office for Mac 2011
Novice
Find and Replace Format macro issue
 
Join Date: Dec 2012
Posts: 2
Jack is on a distinguished road
Default Find and Replace Format macro issue

Disclaimer: I'm new to VBA and macros... Please bear with me. I've tried to research answers to my problem elsewhere, but no luck.



My purpose is to strip my Word document of all formatting, paste it into a text-only text editor, then copy that text and re-paste back into a new Word document. The goal is to have as "clean" a Word document as possible for upload to a third-party website. (Site is Smashwords. I'm trying to expedite their directions for what they term their "nuclear option.")

The particular macros I'm working on are for italics. If I can get these macros to work, I'll modify for bold and underline formats also.

For macro 1:

In Advanced Find and Replace, I do
Find what: [blank]
Format: Italic

and then
Replace with: III^&III

That's macro 1. Basically it's inserting the placeholder tags "III" immediately before and after all italicized text.

For macro 2, I want to re-italicize the text and delete the placeholder "III" tags.

However, for macro 1, I can't get the macro to work. I used the macro recorder. When I do it manually it works fine. But then when I try to run the macro I recorded when I did it manually, nothing happens. Maybe the recorder can't follow when I click on some of the Advanced Find and Replace Format menus?

I haven't even tried doing macro 2 yet, since I can't get macro 1 to work.

Any assistance appreciated. Thanks.
Reply With Quote
  #2  
Old 12-10-2012, 11:44 PM
macropod's Avatar
macropod macropod is offline Find and Replace Format macro issue Windows 7 64bit Find and Replace Format macro issue Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,232
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

The following macro adds a series of tags (bold = <b></b>, italic = <i></i> & underlined = <u></u> - you can change that) to the bold, italic & underlined text in a document, and removes the bold, italic & underlined formatting at the same time.

Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .Text = ""
    .Font.Bold = True
    .Replacement.Text = "<b>^&</b>"
    .Replacement.Font.Bold = False
    .Execute Replace:=wdReplaceAll
    .ClearFormatting
    .Font.Italic = True
    .Replacement.Text = "<i>^&</i>"
    .Replacement.Font.Italic = False
    .Execute Replace:=wdReplaceAll
    .ClearFormatting
    .Font.Underline = True
    .Replacement.Text = "<u>^&</u>"
    .Replacement.Font.Underline = False
    .Execute Replace:=wdReplaceAll
  End With
End With
Application.ScreenUpdating = True
End Sub
If you comment-out the three '.Replacement.Font' lines ending in 'False', the formatting will be retained.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 12-12-2012, 09:24 PM
Jack Jack is offline Find and Replace Format macro issue Mac OS X Find and Replace Format macro issue Office for Mac 2011
Novice
Find and Replace Format macro issue
 
Join Date: Dec 2012
Posts: 2
Jack is on a distinguished road
Default

Thank you for the help.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and Replace Format macro issue Macro to find text and replace with form field containing that text iiiiifffff Word VBA 16 06-04-2016 01:47 AM
Macro to find text in between two characters and then format selected text? qcom Word 5 02-19-2015 11:23 PM
macro or find/replace JamesVenhaus Word 2 02-27-2012 03:34 PM
Find & Replace Insert Issue mipacker Word 0 02-18-2009 08:59 AM
Find and Replace Macro - A Better Way Tribos Word VBA 0 10-08-2008 03:22 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:31 AM.


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