Jump to content
Macro Express Forums

Paste Rich Text in Word 2013


Recommended Posts

I don't know but that sounds like an issue with Word. I know in many Office applications they get clever when you paste things in. Like automatically applying styles and such. Try the same macro in WordPad. Also try pasting in the text manually.

Link to comment
Share on other sites

Thank You, great advice as always!!!

 

It works in Wordpad using a .rtf-file. I never would have thought of this. It must have something to do with the fileformat (doc vs rtf) and what actually is the content of a rich text clipboard. I don´t really understand it but am i happy you showed me the way.

Link to comment
Share on other sites

People often think when you paste in an Office app that is all that happens. That is not the case at all. When you paste into any of them they take what's on the clipboard and analyze it and often change it or even things in the document. Like maybe it sees some RichText with bullet characters. Well it might take this and decide "Ah ha! He wants a numbered list!" And then convert your text to a series of items i a numbered list. Now it might look similar but under the hood they're nothing alike. Not only will it change the string data you sent it but it will also change the styles in Word. Remember Word is a style based word processor. If you ever manually bold a header, change a font or it's size, or add carriage returns to make spaces your not using it correctly. It's all about styles. IE if you want more space after some text change that in the definition of the style your'e using. Everything is in a style in Word. The reason I mention this is Word knows that's the proper way and i'm guessing when pasting formatted text in Word it will probably get clever and change a style.

 

The best example I have is in Excel since I don't often automate Word. You might not realize this but Excel cells are set to a type of data. They are DateTime, Money, Boolean, Numeric, and String. If I have a GL (General Ledger) code of "12RG" Excel takes that and decided it's not a number or any other type of data and brings it in as string. Cool. That's what I intended and need. Now my lookup table works. Then I have a code "2481". Ohhhh now it gets clever and decides that's a number. Then I paste in "MAR2" and although it doesn't look like it to my eye Excel thinks that's a date and changed the cell data type to date and guesses that you mean 2/3/2016 and applies the closest looking date format. Now my cell is a date and it is formatted to look like "2-Mar". IN all these cases my lookup table no longer works. I call it being "clever clever" (said with a haughty English accent).

 

I don't know any way to get around this with MEP. I ended up using a class library in .NET called Interop. It's wonderful. Essentially it's an API that allows a program to do anything a user can. But you need to know how to program in one of the .NET languages to utilize it. If you are ever interested in doing something like this please feel free to contact me outside the forum by giving me your email address in a PM. I'm happy to share my experience for free and maybe even make some small samples for you.

Link to comment
Share on other sites

@ rberq.

 

You may check what format is "Standard" in your word version. This definition ist stored in the document or in new documents in the Normal.dot(m) in Templates. It´s likely that Word uses this format.

 

Also consider that you can define in word which format (source or target) it should use if pasting from other or same (Word) Applications in the preferences of word. By pressing CTRL after pasting you can change that default behaviour manually.

Link to comment
Share on other sites

MEP doesn't have a clipboard variable. But you there are applications that will. I used to use one called ClipMate and you could save several there and I think there was a hotkey sequence to directly access any one of them. One could use that with MEP to get the same effect.

Link to comment
Share on other sites

It would be worth suggesting. However clipboard contents are much more complex than than most realize. EG in Office apps it's something like a DDE link. What it does is to command Excel to send what is selected. IE not the actual value selected. That's how you can 'loose' things you thought you had copied to your clipboard.

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...