×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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

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

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 

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

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

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

Well just pasting it in WILL cause an error, as sess is not the variable object for your code, rather Sess0!

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

replace sess.screen with sess0.screen

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

...also variable vt has not been assigned before you write it to your worksheet!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close