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?

Member Avatar for AlanC

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.