Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SendKeys to Notepad

Status
Not open for further replies.

Andrzejek

Programmer
Joined
Jan 10, 2006
Messages
8,576
Location
US

I open a text file (error log file) in Notepad and move to the end of that file:
Code:
Dim RetVal

RetVal = Shell("NOTEPAD.EXE " & filErrorFile, 1)
SendKeys "^{END}"    [green]'Ctrl-END[/green]

It works fine in VB when I run it, but then I make an EXE file and everything works except moving to the end of text file. Seams to me that SendKeys is ignored in EXE.

Any suggestions?

---- Andy
 
Strange, it is working fine for me in the IDE and as a compiled exe. Have you tried the following:

Code:
Private Sub Command1_Click()
Dim RetVal As Long
Dim filErrorFile As String
filErrorFile = "C:\Test.txt"
RetVal = Shell("NOTEPAD.EXE " & filErrorFile, 1)
[COLOR=red][b]AppActivate RetVal[/b][/color]
SendKeys "^{END}"    'Ctrl-END
End Sub

Swi
 
I did try it - no change :-(

What gets me is: the code works fine and does what I want in VB. Compiled into EXE does not.

Notepad keeps the focus, just does not want to move to the end.

I did try to put Timer and delay the SendKeys for a second, but that did not do anythis.

---- Andy
 
Hmmmm. Quite strange. Let me know if you get a resolution because it seems to be working on my end.

Swi
 
Swi, it works for me, too, your code, I mean. Even when I make an EXE out of it. Why my app does not work, I still do not know.

Here is my whole code. It is in Module, no user interface. Starts from Sub Main. I keep a small text file with the date/time to know if I already checked the log file:
Code:
Option Explicit
Dim datFileDate As Date
Dim strTextLine As String

Const filErrorFile As String = "V:\Error\PSSUserErrorLog.dat"

Sub Main()

On Error GoTo MyErrorHandlr

datFileDate = FileDateTime(filErrorFile)

Open App.Path & "\ErrorFile.txt" For Input As #1
    Line Input #1, strTextLine
Close #1

If strTextLine = datFileDate Then
    If vbYes = MsgBox("You already have seen this file." _
                       & vbCrLf & "" _
                       & vbCrLf & "Want to see it again?" _
                       , vbYesNo Or vbQuestion Or vbDefaultButton2, "Old File") Then
                       
        Call ShowErrorFile
    End If
Else
    Call ShowErrorFile
End If

Exit Sub
MyErrorHandlr:

If Err.Number = 53 Then
    'Text File does not exist
    Call ShowErrorFile
    Exit Sub
End If

End Sub

Private Sub ShowErrorFile()
Dim RetVal

Open App.Path & "\ErrorFile.txt" For Output As #1
    Print #1, datFileDate
Close #1

RetVal = Shell("NOTEPAD.EXE " & filErrorFile, 1)
AppActivate RetVal
SendKeys "^{END}"

End Sub

---- Andy
 
I just compiled the code and it works fine for me too. (W2000)

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Have you tried putting in a delay between;

RetVal = Shell("NOTEPAD.EXE " & filErrorFile, 1)

and

AppActivate RetVal

and

SendKeys "^{END}"

Hugh,
 
I did try to delay SendKeys "^{END}" for 1 sec after opening text file in Notepad, but there was no difference.

I guess I will have to give it up since it is not that important, after all. Not the end of the world :-)
Especially that others took my code and it worked OK for them.


Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top