JREF Homepage Swift Blog Events Calendar $1 Million Paranormal Challenge The Amaz!ng Meeting Useful Links Support Us
James Randi Educational Foundation JREF Forum
Forum Index Register Members List Events Mark Forums Read Help

Go Back   JREF Forum » General Topics » Computers and the Internet
Click Here To Donate

Notices


Welcome to the JREF Forum, where we discuss skepticism, critical thinking, the paranormal and science in a friendly but lively way. You are currently viewing the forum as a guest, which means you are missing out on discussing matters that are of interest to you. Please consider registering so you can gain full use of the forum features and interact with other Members. Registration is simple, fast and free! Click here to register today.

Tags word , macro , help

Reply
Old 14th January 2007, 07:04 PM   #1
Charlie Monoxide
Wag
 
Charlie Monoxide's Avatar
 
Join Date: Jul 2003
Location: London, Ontario
Posts: 2,761
Word Macro Help

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
__________________
Major General Wag of JREF
Charlie Monoxide is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top
Old 14th January 2007, 08:41 PM   #2
Wavicle
Critical Thinker
 
Join Date: Mar 2006
Posts: 341
Originally Posted by Charlie Monoxide View Post
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:

Code:
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.)
Wavicle is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top
Old 15th January 2007, 07:21 AM   #3
Charlie Monoxide
Wag
 
Charlie Monoxide's Avatar
 
Join Date: Jul 2003
Location: London, Ontario
Posts: 2,761
Originally Posted by Wavicle View Post
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
__________________
Major General Wag of JREF
Charlie Monoxide is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top
Reply

JREF Forum » General Topics » Computers and the Internet

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 11:50 PM.
Powered by vBulletin. Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
© 2001-2012, James Randi Educational Foundation. All Rights Reserved.

Disclaimer: Messages posted in the Forum are solely the opinion of their authors.