Write to notepad and keep it open on the desktop

MattMax

New Member
Joined
Nov 13, 2009
Messages
34
Hello,

I have a macro that normalizes a data file in excel for upload to a web server. Ideally I would like something light like notepad to open as the macro is running and print out directions/steps for the user to take after the macro completes.

for example...

"This file contains x amount of records..
"step 1. Log into the "Application Name"
"step 2. ....
""
Depending on the file type there may be different directions so I want to create the instruction txt based on the file type the user is dealing with.

Long short of it... other then using send keys, is there a way I can print txt to the notepad. I do not want to save this notepad doc and obviously I don't want to close it after the macro runs...

I know how to open it.. shell(notepad.exe).... , but how do I write to it?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
With Notepad open you would need to use SendKeys
Could write to a text file & then open in Notepad at the end.
Could write to a Word document.
 
Upvote 0
Code:
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 SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const WM_SETTEXT = &HC
Private Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE

Public Sub DPTN(ByVal Text As String, hWnd As Long)
    Dim EditHwnd As Long
    Dim CurrentWindowText As String
    Dim lngLength As Long
    
    EditHwnd = FindWindowEx(hWnd, 0, "Edit", vbNullString)
    lngLength = SendMessage(EditHwnd, WM_GETTEXTLENGTH, ByVal 0, ByVal 0)
    CurrentWindowText = Space(lngLength)
    SendMessage EditHwnd, WM_GETTEXT, ByVal lngLength + 1, ByVal CurrentWindowText
    Text = CurrentWindowText & Text & vbCrLf
    SendMessage EditHwnd, WM_SETTEXT, ByVal Len(Text) + 1, ByVal Text
End Sub

The above will write text to notepad given the handle. You will need to get the handle from the instance in this case. See <A HREF="http://support.microsoft.com/kb/242308" TARGET="_blank">How To Find a Window Handle from an Instance Handle</A>
 
Upvote 0

Forum statistics

Threads
1,215,276
Messages
6,124,007
Members
449,139
Latest member
sramesh1024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top