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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need a macro to open a Notepad file and accept copied text.

Status
Not open for further replies.

JeaShe

Programmer
Mar 9, 2004
89
US
I have many macros that open Word or Excel and I send data to those programs and retrieve data from them. However, I now need a macro where I can open the same text file (saved to the desktop) and after compiling data in Extra session, paste that data into the text file.
I've been able to open Notepad thus far. But I can't open a particult Notepad file nor paste data to that file. Then I'll wantto save it and leave the Notepad file open but close Extra macro.
These are the lines in the Extra macro that will open Notepad:

dim rc as variant
rc = Shell("notepad.exe", 3)

Thank you!

Jeane
 
the file does not actually open when i write to it. I'm not sure if you can actually write to a text file if the file is open but this is how i would write it.

Code:
Sub Main
    
    MyFilePath = "C:\"
    MyFileName = "test.txt"
    
    MyFile = MyFilePath & MyFileName
    
    Open MyFile for Append as #1
    
        Print #1, "[             the time is  " & Format(time,"hh:mm:ss AM/PM" ) & "                                    ]"
        
        for i = 1 to 24
            MyLine = sess.screen.getstring(i,1,80)
            Print#1, MyLine
        next i
    
    Close #1
    
    Shell("Notepad C:\test.txt")
    
    
End Sub
 
Unfortunately I cannot use this code as is. When I paste it in to an Extra macro it won't compile. Would you mind creating it in the Extra environment? I'll provide some standard code for establishing objects below. This code shows standard macro declarations in Extra and then Excel plus has a line to enter variable data into an Excel cell.

So I know how to do this with Excel and Word, however, cannot seem to do the same with Notepad.

'--------------------------------------------------------------------------------
' GLOBAL VARIABLE DECLARATIONS
Global g_HostSettleTime%
Global g_szPassword$

Option Explicit

Dim objExcel as Object, objWorkBook as Object, scrErr as String
Dim Sess0 as Object, xlRow as Integer, OldSystemTimeout&

Sub Main()
'--------------------------------------------------------------------------------
' GET THE MAIN SYSTEM OBJECT
Dim Sessions as Object, System As Object
Set System = CreateObject ("EXTRA.System")

If (System is Nothing) Then
Msgbox "Could not create the EXTRA object. Macro will Stop now."
Stop
End If
Set Sessions = System.Sessions

If (Sessions is Nothing) Then
Msgbox "Could not create the Sessions collection object. Macro will Stop now."
Stop
End If
'--------------------------------------------------------------------------------
'SET THE DEFAULT WAIT TIMEOUT VALUE
g_HostSettleTime = 200 ' MILLISECONDS

OldSystemTimeout& = System.TimeoutValue
If (g_HostSettleTime > OldSystemTimeout) Then
System.TimeoutValue = g_HostSettleTime
End If

' GET THE NECESSARY SESSION OBJECT
Set Sess0 = System.ActiveSession
If (Sess0 is Nothing) Then
Msgbox "Could not create the Session object. Macro will Stop now."
Stop
End If

If Not Sess0.Visible Then Sess0.Visible = TRUE
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

objWorkBook.Worksheets ("Sheet1").Cells (xlrow, 25) = vt
 
Well just pasting it in WILL cause an error, as sess is not the variable object for your code, rather Sess0!
 
...also variable vt has not been assigned before you write it to your worksheet!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top