0

Is it difficult to write to the system clipboard?

Also, once that is done, how about launching Notpad from VB and dynamically doing a paste (I guess via DDE) from VB code?

2
Contributors
1
Reply
3
Views
11 Years
Discussion Span
Last Post by AlanC
0

Hi Complete

To do simple stuff with text is easy. There are 3 methods for use with the clipboard, Clipboard.Clear , Clipboard.SetText and Clipboard.GetText().

The SetText method writes to the clipboard. Suppose you have a textbox (Text1) full of text, to save it to the clipboard is simply

Clipboard.SetText Text1.Text

To launch notepad with text from the clipboard, it's probably easiest to create a temporary file and launch using shell.

Open a new project, add a text box (text1) and a command button (command1) and this code:

Private Sub Command1_Click()
   Clipboard.SetText Text1.Text
   Dim sTemp As String
   'retrieve clipboard text content
   sTemp = Clipboard.GetText()

   'save it to a temporary file
   Open App.Path & "\temp.txt" For Output As #1
   Print #1, sTemp
   Close #1

   'launch this file in notepad
   Shell "notepad.exe " & App.Path & "\temp.txt", vbNormalFocus
   'delete the temp file
   Kill App.Path & "\temp.txt"
End Sub

There's a lot more functionality in the API, you might want to google around for this.

Hope this helps,
AlanC

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.