Solved

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

Posted on 1998-07-01
3
1,323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

730 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