margaret Posted May 10, 2010 Report Share Posted May 10, 2010 Is it possible to have a macro "know" that text it copied is italicized, so that when it pastes the text somewhere else, it will still be italicized even though that text has been manipulated as a variable in between? In the macro, I put the copied text into a variable and then do various tests and manipulations to it before pasting the result into another program. As it stands, the text loses italics in the process. If the macro can determine that the text is italicized, I could set a flag in the beginning of the macro so that it could re-italicize it before pasting. Thanks. Quote Link to comment Share on other sites More sharing options...
paul Posted May 11, 2010 Report Share Posted May 11, 2010 Is it possible to have a macro "know" that text it copied is italicized How on earth would it know that? When you say the text is italicized, you mean that the text is prefixed and suffixed with codes that tell the target program to italicize the text. But the codes differ from one program to another. Word's codes for italizing text are quite different to, say, XyWrite. So this is going to work for you only if: - the target program is always the same, e.g. Word - you know what codes Word uses to italicize text - you can force the copy to include those codes rather than just the text itself LOL! Quote Link to comment Share on other sites More sharing options...
rberq Posted May 11, 2010 Report Share Posted May 11, 2010 If you have ME copy to clipboard, from a Word document, then Alt-Tab to another Word document and type from the clipboard, the italics are kept. Once you move the text from the clipboard to a ME text variable, the italics are gone even if you then move the text back to the clipboard again. Even with the Word-to-Word copy, I suspect MS-Office is using its own clipboard stack to carry the text, rather than the Windows clipboard. Quote Link to comment Share on other sites More sharing options...
margaret Posted May 11, 2010 Author Report Share Posted May 11, 2010 How on earth would it know that? When you say the text is italicized, you mean that the text is prefixed and suffixed with codes that tell the target program to italicize the text. But the codes differ from one program to another. Word's codes for italizing text are quite different to, say, XyWrite. So this is going to work for you only if: - the target program is always the same, e.g. Word - you know what codes Word uses to italicize text - you can force the copy to include those codes rather than just the text itself LOL! I don't see what's funny about it. Just trying to do what the users need. What I was looking for was some way for the macro to set a flag if the text was italicized (an "IF" loop), so that it could be re-italicized later. Obviously, if the macro cannot recognize the italics in the first place, no such thing is possible; the target programs are never the same, and I have no idea what codes the copy-from program uses, though I do know the ones the copy-to program uses. So, the answer is NO. Essentially, the only way I can retain the italics is to simply paste the clipboard as is and not have the macro clean it up. Rats. Thanks for your reply. Quote Link to comment Share on other sites More sharing options...
margaret Posted May 11, 2010 Author Report Share Posted May 11, 2010 If you have ME copy to clipboard, from a Word document, then Alt-Tab to another Word document and type from the clipboard, the italics are kept. Once you move the text from the clipboard to a ME text variable, the italics are gone even if you then move the text back to the clipboard again. Even with the Word-to-Word copy, I suspect MS-Office is using its own clipboard stack to carry the text, rather than the Windows clipboard. Yes, I know the italics are gone! That was my question, can we get around that? Obviously the answer is no. This is not a Word-to-Word or even Office-to-Office situation. The copy-from program and the copy-to program are entirely different (and neither is a Microsoft program). However, if I don't stuff the clipboard into a variable, the italics are kept, at least in this particular situation. Thanks. Quote Link to comment Share on other sites More sharing options...
acantor Posted June 1, 2010 Report Share Posted June 1, 2010 I think it may be possible for macro express to detect whether text is italicized, under certain conditions, and in certain contexts. I am thinking out loud here, so these ideas may not work in the real world, but this is what I have in mind: Let's assume that we want this to work in Microsoft Word. Use VBA (the macro language built into Microsoft Word) to detect the character formatting of a selection. If it is italics, add a space or some other character to the end of the selection. This Word macro is activated by a hotkey, say "F12." So the Macro Express script does this: 1. Copy the selection to the Clipboard. 2. Place it in variable T1 3. Press F12. 4. Copy the selection to the clipboard. 5. Place it in a variable T2 6. Replace the selection in the document with T1. 7. Compare the length of T1 and T2. If T2 > T1, then the selection was italicized. Quote Link to comment Share on other sites More sharing options...
acantor Posted June 2, 2010 Report Share Posted June 2, 2010 Let's assume that we want this to work in Microsoft Word. Use VBA (the macro language built into Microsoft Word) to detect the character formatting of a selection. If it is italics, add a space or some other character to the end of the selection. This Word macro is activated by a hotkey, say "F12." This might work as the VBA part. Assign the macro to F12 (through the "Customize Keyboard" feature in Word.) Sub IfSelectionIsItalicsAddPeriod() ' If the selection contains italicized text, append a period to the end of the selection If Selection.Font.Italic = -1 Then Selection = Selection & "." End If End Sub My proposed solution is definitely not elegant! But better a kludgy macro that does the job than having nothing! Hopefully others refine the idea. Quote Link to comment Share on other sites More sharing options...
margaret Posted June 2, 2010 Author Report Share Posted June 2, 2010 This might work as the VBA part. Assign the macro to F12 (through the "Customize Keyboard" feature in Word.) Sub IfSelectionIsItalicsAddPeriod() ' If the selection contains italicized text, append a period to the end of the selection If Selection.Font.Italic = -1 Then Selection = Selection & "." End If End Sub My proposed solution is definitely not elegant! But better a kludgy macro that does the job than having nothing! Hopefully others refine the idea. Yes, I think that concept would work -- but it doesn't help in my situation. I cannot involve Word in this particular process; the combination of Word and the other programs just doesn't work, too many memory-hogging programs trying to hog the same memory. Even if I could, it might make the macro too slow because the only reason to dip into Word at all would be for the italics. I just made a different macro that will re-italicize the text after it comes out of the cleanup-variable process; in other words, the user chooses a different macro if they want the final text to be italicized. Thanks for the idea, though. Quote Link to comment Share on other sites More sharing options...
patrickbarrett Posted June 2, 2010 Report Share Posted June 2, 2010 I don't know of a way that you can figure out which text is italics, but if you know the range or the text you can always type it back out with italics via text type: <TEXTTYPE:Testing 123 <CTRLD>i<CTRLU>Testing<CTRLD>i<CTRLU>> Quote Link to comment Share on other sites More sharing options...
acantor Posted June 2, 2010 Report Share Posted June 2, 2010 I just made a different macro that will re-italicize the text after it comes out of the cleanup-variable process; in other words, the user chooses a different macro if they want the final text to be italicized. That sounds like an excellent compromise. The perpetual problem for people who script macros is that we have limited programmatic access to the applications we are scripting for. Therefore, we are forced to use indirect ways to do what we wish we could do directly. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.