Solved

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

Posted on 1998-07-01
3
1,249 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
Comment Utility
You could probably get better results posting this question in the programming section.
0
 
LVL 1

Expert Comment

by:sparko
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article will show you how to use shortcut menus in the Access run-time environment.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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.
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…

744 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

17 Experts available now in Live!

Get 1:1 Help Now