Solved

VBA f() to use clipboard to get RTF codes for range text

Posted on 1998-07-01
3
1,301 Views
Last Modified: 2008-02-01
I need a VBA function which uses the clipboard to get RTF codes for range text e.g. something like:
   e.g. to get onto clipboard
   m_oWordPara.Range.Copy

   now once its on the clipboard, I want retreive the RTF representation of the text into a simple VBA string variable.
0
Comment
Question by:abulka
  • 2
3 Comments
 
LVL 1

Expert Comment

by:jmcguir
ID: 1612652
You could probably get better results posting this question in the programming section.
0
 
LVL 1

Expert Comment

by:sparko
ID: 1612653
Thanks jmcquir, if you post a comment as an answer the questions cannot be answered.  I have written the code for abulka to do what he is asking,  and until he clears your answer I cannot post it as an answer.  Please could you check the comment box if not posting an actual answer. Cheers Sparko
0
 
LVL 1

Accepted Solution

by:
sparko earned 200 total points
ID: 1612654
mmm hope I wasnt too harsh on jmcquir.  Anyway I dont know if you`ve called the windows API from a VBA program before, but basically you are calling DLL`s which have to have delclare statements to specify the routines you are calling.  These need to go at the top of your module. and are as follows:-


Declare Function RegisterClipboardFormat Lib "user32" Alias "RegisterClipboardFormatA" (ByVal lpString As String) As Long
Declare Function GetActiveWindow Lib "user32" () As Long
Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Declare Function CloseClipboard Lib "user32" () As Long
Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As String

'The following code gets the data from the clipboard in the right format and puts it in string s

Dim Fmt As Long   ' variable for RTF format clipboard handle
Dim S As String   ' string to get RTF data into, could be any string you like

Fmt = RegisterClipboardFormat("Rich Text Format") ' note this only has to be done once, not for each paragraph

' these three lines or the equivalent (as you may not copy all strings to s) need to be done for each paragraph
Call OpenClipboard(GetActiveWindow()) ' open clipboard using a convenient window handle
S = GetClipboardData(Fmt) ' get data from clipboard to string in rtf format
Call CloseClipboard ' close clipboard

'NB: remember to open and close the clipboard after getting each 'string, and make sure that you do not forget to close the 'clipboard if you have any error trapping after the open!!

Cheers Sparko.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction It seems that at least a couple of times per month, I answer a question that requires automating Outlook from another Microsoft Office application, usually (although not always) to send one or more email messages.  For example: …
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question