![]() ![]() Private Declare Function GlobalFree Lib "kernel32" Alias "GlobalFree" ( _ Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long ![]() Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _īyVal Destination As Long, Source As Any, ByVal Length As Long) Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, _ Private Declare Function SetClipboardData Lib "user32" ( _īyVal wFormat As Long, ByVal hMem As Long) As Long Private Declare Function CloseClipboard Lib "user32" () As Long Private Declare Function Empt圜lipboard Lib "user32" () As Long "RegisterClipboardFormatA" (ByVal lpString As String) As Long Private Declare Function RegisterClipboardFormat Lib "user32" Alias _ Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long Set oWord = CreateObject("word.application")Īdd the following code to the General Declarations section of the Form module. HGlobal = GlobalAlloc(GMEM_MOVEABLE Or GMEM_DDESHARE, Len(sRTF))ĬopyMemory lpString, ByVal sRTF, Len(sRTF) LRTF = RegisterClipboardFormat("Rich Text Format") ![]() 'Copy the contents of the Rich Text to the clipboard 'sRTF represents the rich-text-formatted string to paste into Word By default, a form that is named Form1 is created.Īdd a CommandButton to the form, double-click the CommandButton, and then add the following code to the Click event. Start Visual Basic, and then create a new Standard EXE. To create the example project, follow these steps: This article describes how to build a simple Visual Basic example that starts Word, creates a new document, and adds some formatted text to the document by using a pre-built RTF string. You can create an RTF string, copy the RTF string to the clipboard, and then paste the RTF string into the document. If you can represent the data as a Rich Text Format (RTF) string, you can frequently reduce the Automation code. However, if you have lots of text that you want to enter and to format, it might require lots of code. With Automation, you can do programmatically almost anything that the user can do manually in Microsoft Office Word. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |