View Full Version : Word Macro Help
Charlie Monoxide
14th January 2007, 07:04 PM
I'm trying to write a Word 2003 macro that will find all italic text and just add a single space in front of the italic text.
Before: some crazy textITALIC, some moreITALIC.
After : some crazy text ITALIC, some more ITALIC.
S'cuse my lack of HTML skills to even show the example with real italics.
The reason I need the macro is that I have some books stored in LIT format. I have a spiffy utility that converts the LIT files to RTF, but somehow flows italics into the previous word or symbol.
Any help will be appreciated ....
Charlie (lost in MS Word VBA) Monoxide
Wavicle
14th January 2007, 08:41 PM
I'm trying to write a Word 2003 macro that will find all italic text and just add a single space in front of the italic text.
Before: some crazy textITALIC, some moreITALIC.
After : some crazy text ITALIC, some more ITALIC.
S'cuse my lack of HTML skills to even show the example with real italics.
The reason I need the macro is that I have some books stored in LIT format. I have a spiffy utility that converts the LIT files to RTF, but somehow flows italics into the previous word or symbol.
Any help will be appreciated ....
Charlie (lost in MS Word VBA) Monoxide
I'm not really a VBA guy, but here's my clumsy hacked attempt at this:
Sub italicSpacer()
'
' italicSpacer Macro
' Macro created 1/14/2007 by Joe Burks
'
Dim blnSearchAgain As Boolean
' Search from the top of the document
Selection.HomeKey Unit:=wdStory
' Change this to False if you want to replace one-by-one
blnSearchAgain = True
Do
' Search for some italicized text
With Selection.Find
.ClearFormatting
.Text = ""
.Font.Italic = True
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Execute
End With
If Selection.Find.Found Then
' If some was found, put a space in front of it
Selection.Text = " " + Selection.Text
Selection.MoveRight
Else
' Nothing found, we're done!
blnSearchAgain = False
End If
Loop While blnSearchAgain
End Sub
Give it a shot, it seems to work with your example. This is probably my first VBA script since Word 5 (circa 1995), so take with appropriate sized grain of salt (maybe someone here who actually likes this sad excuse for Basic can fix any problems herein.)
Charlie Monoxide
15th January 2007, 07:21 AM
I'm not really a VBA guy, but here's my clumsy hacked attempt at this:
code removed ....
Give it a shot, it seems to work with your example. This is probably my first VBA script since Word 5 (circa 1995), so take with appropriate sized grain of salt (maybe someone here who actually likes this sad excuse for Basic can fix any problems herein.)Works great! Much appreciated for the quick response!
You'll go to heaven if you're so inclined to believe ....
Charlie (off to format some LIT files) Monoxide
© 2001-2009, James Randi Educational Foundation. All Rights Reserved.
vBulletin® v3.7.7, Copyright ©2000-2013, Jelsoft Enterprises Ltd.