![]() |
#1
|
|||
|
|||
![]()
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. |
#2
|
||||
|
||||
![]()
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Thank you for the help.
|
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
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 |