?
Solved

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

Posted on 1998-07-01
3
Medium Priority
?
1,444 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 800 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
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 …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

850 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