• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 148
  • Last Modified:

How to load a string into the default text editor

I'l like to load a string straight into the users default text editor (or if necessary notepad)

I can do this by saving as a file but I'd like to by pass this and put the string straight into the users default editor.
They can then choose whether to save the file.
  • 3
1 Solution
I'm not entirely sure what you mean, but would putting something into the users clipboard be acceptable?

    Clipboard.SetText "Default text would go in here."

Your users then just need to paste this anywhere they wish.
colindowAuthor Commented:
As it happens this is what I'm doing at the moment. What I would like to do is present them with the default text editor with the text loaded.

I do something similar where I create an instance of excel to give the user results. If they save the file they have a copy. If they don't there is nothing left on their disk.

In this case I need to work out the app to use (i.e. the defualt text editor) then apply the text string to an empty document.
The registry entry [HKEY_CLASSES_ROOT\txtfile\shell\open\command] contains the default editor to open a textfile. Can you query this key to find the app, then use this to input the default text you require?
A little extra just to be aware.. if you google search that registry location, you'll find the first 50 entries or so solely talk about a virus/worm.. this might make searching for help on this subject a little tougher :(
Try this:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessageSTRING Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const WM_SETTEXT = &HC

Private Sub Command1_Click()
Dim lNotepadHwnd As Long, lNotepadEdit As Long
Shell "Notepad.exe", vbNormalFocus
lNotepadHwnd = FindWindow("Notepad", vbNullString)
lNotepadEdit = FindWindowEx(lNotepadHwnd, 0&, "Edit", vbNullString)
SendMessageSTRING lNotepadEdit, WM_SETTEXT, 256, "This is The Text I want to send"

End Sub

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now