Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Jun 2001
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macro to insert italicized '' '' (Word 2002)

    <P ID="edit" class=small>(Edited by jscher2000 on 22-Aug-04 12:11. Subject line expanded with more detail.)</P>Hi everyone,

    I am trying to create a macro in Word that does the following:

    Italicize, Open Quotes, start typing, Close Quote, Stop Italicize so that I can continue typing the rest of the paragraph.

    My thought was to simply do:

    Italicize, Quotes/Quotes, Italicize, arrow left, start typing, press the end key to pass the quotes and then continue typing the rest of the paragraph. But because word saves the codes within the paragraph mark, obviously, that does not work for me.

    Can anyone help? I really appreciate any help that you can give me.

    Thank you

    Maria

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Macro to insert italicized '' '' (Word 2002)

    All except the last step. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Word macros do not supply an easy way to pause and resume from inside a macro while providing access to the document. So as you've discovered, you can have a macro that does the first four steps -- Turn on italics, type quotation mark, type quotation mark, back arrow -- but to make the macro pause and wait at that point requires some unconventional thinking. You could show a toolbar button in the "down" ("in") position, similar to the usual bold and italic toolbar buttons, and have your macro cycle in the background waiting for that button to be released back to the up position by you, and then exit the quotation marks, turn off italics, and stop running. I've never written code like that, but it's the only solution that comes to mind that lets you work inside Word. It could slow down Word's performance, but since it's only temporary, perhaps that would be acceptable.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to insert italicized '' '' (Word 2002)

    You could use InputBox to ask for the text between the quotes:

    Sub QuoteItalic()
    Selection.Font.Italic = True
    Selection.TypeText Text:=Chr(34) & InputBox("Provide text to be placed between quotes") & Chr(34)
    Selection.Font.Italic = False
    End Sub

  4. #4
    Star Lounger
    Join Date
    Jun 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to insert italicized '' '' (Word 2002)

    What about using a button to toggle the state.
    For example;
    First press Checks a custom property if its ON or non-existant then create it and give it an ON value
    This coincides with the quotation marks/italics.

    Next press toggles this custom property to OFF ... etc

  5. #5
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to insert italicized '' '' (Word 2002)

    Hi Maria,

    The following macro intercepts the Italic command, so will run whenever you press the "I" button or type Ctrl-I on the keyboard. If you're at the beginning of an empty paragraph, an italicized quotation mark is inserted, and then you can type the text of the quote. When you press Ctrl-I again, the macro will insert an italicized quotation mark and then go back to un-italic. If you're not beginning a paragraph or ending a quote, then the macro just does the usual toggling of italic.

    You may, of course, need to adjust this for your own particular needs. I just hacked it together, and it's a bit ugly, but it works.

    HTH!

    <pre>Sub Italic()
    Dim sel As Selection
    Dim rng As Range
    Set sel = Selection
    If sel.Paragraphs.Count > 1 Then
    sel.Font.Italic = wdToggle
    Exit Sub
    End If

    If sel.Paragraphs(1).Range.Characters.Count = 1 Then
    sel.Font.Italic = True
    sel.TypeText (Chr(34))
    Else
    Set rng = sel.Document.Range(sel.Paragraphs(1).Range.Start, sel.Range.End)
    If rng.Font.Italic = True And rng.Characters.First = Chr(34) Then
    sel.TypeText (Chr(34))
    sel.Font.Italic = False
    Else
    sel.Font.Italic = wdToggle
    End If
    End If

    End Sub
    </pre>


  6. #6
    2 Star Lounger
    Join Date
    Jun 2001
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to insert italicized '' '' (Word 2002)

    Thank you guys. You are great.

    I am going to use the input box approach because I understand it, however, the macro puts a space inside the quotes and I cannot see why. Any suggestions? I had to modify the macro a little bit because I need a space before it starts the quote and then at the end after the quotes. It does not matter if I put the line in or not. This is what I get: " this is the text." I have been unable to make the macro not put a space inside the quotes.

    Again, thank you very much.

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to insert italicized '' '' (Word 2002)

    Sorry, I can't explain why the code would insert a space inside the quotes; it doesn't do that for me. I you want spaces outside the quotes, you can use something like this:

    Sub QuoteItalic()
    Selection.TypeText Text:=" "
    Selection.Font.Italic = True
    Selection.TypeText Text:=Chr(34) & InputBox("Provide text to be placed between quotes") & Chr(34)
    Selection.Font.Italic = False
    Selection.TypeText Text:=" "
    End Sub

  8. #8
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    Re: Macro to insert italicized '' '' (Word 2002)

    Hi Maria,

    Hans' code worked without spaces on my XP -- is it possible you've inadvertently typed a space at the beginning or end of your Input? You can't always control what a user will do, so you could modify Hans' code slightly to trim spaces off the beginning and end.

    Sub QuoteItalic()
    Dim strText
    strText = InputBox("Provide text to be placed between quotes")
    strText = Trim(strText)
    Selection.Font.Italic = True
    Selection.TypeText Text:=Chr(34) & strText & Chr(34)
    Selection.Font.Italic = False
    End Sub

    This will trim any spaces inserted at the beginning or end of the text to be formatted.

    Kim

  9. #9
    2 Star Lounger
    Join Date
    Jun 2001
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to insert italicized '' '' (Word 2002)

    Thank you. Thank you. Thank you. The trim code did the trick.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •