The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.
I posted this in G&T awhile back and while we got close to a solution, it never clicked.
I'm in Word 2007. I want a simple macro that will let me take any selected text and wrap it in <i> </i> tags. In other words, it will take SELECTED TEXT and replace it with <i>SELECTED TEXT</i>.
Umm, the keystrok for activating the macro couldn't be easier than simply pressing CTRL + I could it? Unless this is part of a macro that will also identify and make the selection.
Umm, the keystrok for activating the macro couldn't be easier than simply pressing CTRL + I could it? Unless this is part of a macro that will also identify and make the selection.
The OP is looking for help to add HTML tags to his document, not just use Word formatting to change it to italics (unless I misread).
Regardless, Natsus' macro works fine in Word 2007. I tested it, once I found the damn macros menu!
embrik on
"Damn you and your Daily Doubles, you brigand!"
I don't believe it - I'm on my THIRD PS3, and my FIRST XBOX360. What the heck?
Umm, the keystrok for activating the macro couldn't be easier than simply pressing CTRL + I could it? Unless this is part of a macro that will also identify and make the selection.
The OP is looking for help to add HTML tags to his document, not just use Word formatting to change it to italics (unless I misread).
Regardless, Natsus' macro works fine in Word 2007. I tested it, once I found the damn macros menu!
Yeah I haven't installed Office 2007, so I wasn't sure if the menus were the same or not. Hope this is what you were looking for Drez.
Sub sexyprogram()
If Right(Selection, 1) = " " Or Right(Selection, 1) = Chr(13) Then
Selection = " <i>" & Left$((Selection), (Len(Selection) - 1)) & "</i> "
Else
Selection = " <i>" & Selection & "</i> "
End If
End Sub
There's probably a better way but when you reach the end of the line it seems to place a carriage return marker when you select the text, this will check if the selection has a carriage return in the last position, if it does it'll remove it.
I can't get it to add the carriage return you're seeing... Youre sure it's not just in a point in your doc where it feels the need to wrap around to the next line? Stupid question, I know.
Also, for the love of God, please give your macro a better entry point name than "macro1." The programmers of the world will love you just that much more.
It appears to do it in the version of Word we're running (2003 I think) at work. To see if it does it on your version, write out some text, then go to the last character and hit delete, make sure nothing follows it. Now try.
On this version of word it picks up a carriage return at the end of the selection. Stupid, but true!
Any idea why? Adding in the little if statement above seemed to fix it (the chr(13) one, the " " could probably be taken out, I used it when I was testing stuff but it should keep things tidy) but I have no idea why it does it.
Any idea why? Adding in the little if statement above seemed to fix it (the chr(13) one, the " " could probably be taken out, I used it when I was testing stuff but it should keep things tidy) but I have no idea why it does it.
Nah, it's just dumb that way. Probably a bizarre compatibility thing, to give it an honest guess.
Pheezer on
IT'S GOT ME REACHING IN MY POCKET IT'S GOT ME FORKING OVER CASH
CUZ THERE'S SOMETHING IN THE MIDDLE AND IT'S GIVING ME A RASH
Also, for the love of God, please give your macro a better entry point name than "macro1." The programmers of the world will love you just that much more.
I actually left it macro1 for the user to rename it to whatever he wants, but you're right I probably should of named it, "yourprogramname" or something like that 8-)
Anyway Mr_Grinch's code is good. It gets rid of the carriage return problem. I didn't realize it was happening in a different versions of Word =P
Now what would be nice is if you could select multiple text and then run the macro to add the tags at the end of all of them, but I'm not sure if that's even possible.
Posts
Goto tools -> macros -> visual basic editor
paste this code in:
Sub macro1()
Selection = " <i>" & Trim(Selection) & "</i> "
End Sub
Then just select text and run macro. (if you want to rename macro, rename macro1)
The OP is looking for help to add HTML tags to his document, not just use Word formatting to change it to italics (unless I misread).
Regardless, Natsus' macro works fine in Word 2007. I tested it, once I found the damn macros menu!
I don't believe it - I'm on my THIRD PS3, and my FIRST XBOX360. What the heck?
Yeah I haven't installed Office 2007, so I wasn't sure if the menus were the same or not. Hope this is what you were looking for Drez.
Sub sexyprogram()
If Right(Selection, 1) = " " Or Right(Selection, 1) = Chr(13) Then
Selection = " <i>" & Left$((Selection), (Len(Selection) - 1)) & "</i> "
Else
Selection = " <i>" & Selection & "</i> "
End If
End Sub
There's probably a better way but when you reach the end of the line it seems to place a carriage return marker when you select the text, this will check if the selection has a carriage return in the last position, if it does it'll remove it.
Only tested quickly
PSN: SirGrinchX
Oculus Rift: Sir_Grinch
Also, for the love of God, please give your macro a better entry point name than "macro1." The programmers of the world will love you just that much more.
On this version of word it picks up a carriage return at the end of the selection. Stupid, but true!
PSN: SirGrinchX
Oculus Rift: Sir_Grinch
CUZ THERE'S SOMETHING IN THE MIDDLE AND IT'S GIVING ME A RASH
PSN: SirGrinchX
Oculus Rift: Sir_Grinch
Nah, it's just dumb that way. Probably a bizarre compatibility thing, to give it an honest guess.
CUZ THERE'S SOMETHING IN THE MIDDLE AND IT'S GIVING ME A RASH
I actually left it macro1 for the user to rename it to whatever he wants, but you're right I probably should of named it, "yourprogramname" or something like that 8-)
Anyway Mr_Grinch's code is good. It gets rid of the carriage return problem. I didn't realize it was happening in a different versions of Word =P
Now what would be nice is if you could select multiple text and then run the macro to add the tags at the end of all of them, but I'm not sure if that's even possible.