Jump to content
Macro Express Forums

saving italics when manipulating text in variable?


margaret

Recommended Posts

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 weeks later...

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...