Solved

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

Posted on 1998-07-01
3
1,269 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now