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

open exel or. TXT from Attachmate

Status
Not open for further replies.

lestatjt

Technical User
Apr 4, 2012
8
FR
hello,
I am looking for a code to open a. txt or Excel from a macro
gender

Sub Main
Open "\\c:010011\MyDocs\mot de passe\base.txt"
End Sub

thank you for all the response

ps. I spend a script or excel to Attachmate

' Déclarations des variables globales
Global g_HostSettleTime%
Global g_szPassword$

Sub valide()
'--------------------------------------------------------------------------------
' Cherche l'objet principal du système
Dim Sessions As Object
Dim System As Object
Set System = CreateObject("EXTRA.System") ' Cherche l'objet du système
If (System Is Nothing) Then
MsgBox "Impossible de créer l'objet du système EXTRA. L'exécution de la macro est interrompue."
Stop
End If
Set Sessions = System.Sessions

If (Sessions Is Nothing) Then
MsgBox "Impossible de créer l'objet de la collection Sessions. L'exécution de la macro est interrompue."
Stop
End If
'--------------------------------------------------------------------------------
' Définir la valeur du délai d'attente par défaut
g_HostSettleTime = 0 ' millisecondes

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

' Cherche les objets nécessaires pour la session

Dim NO_IMMA
NO_IMMA = Workbooks("remp refp").Sheets("valide").Range("b2").Value
Dim NO_COMPTE
NO_COMPTE = Workbooks("remp refp").Sheets("valide").Range("b3").Value
Dim KMS
KMS = Workbooks("remp refp").Sheets("valide").Range("b4").Value
Dim code1
code1 = Workbooks("remp refp").Sheets("valide").Range("b5").Value
Dim code2
code2 = Workbooks("remp refp").Sheets("valide").Range("b6").Value
Dim code3
code3 = Workbooks("remp refp").Sheets("valide").Range("b7").Value
Dim code4
code4 = Workbooks("remp refp").Sheets("valide").Range("b8").Value
Dim code5
code5 = Workbooks("remp refp").Sheets("valide").Range("b9").Value



Dim Sess0 As Object
SessName0$ = "TN3270_A.EDP"

Set Sess0 = Sessions.Item(SessName0$)
If Sess0 Is Nothing Then
Err = MsgBox(SessName0 + " n'est pas ouvert. Souhaitez-vous l'ouvrir ?", 1)
If 1 = Err Then
Err = 0
Set Sess0 = Sessions.Open(SessName0)
If Err Then
MsgBox ("Echec de l'ouverture " + SessName0 + ". Interruption de la simulation")
Stop
End If
ElseIf 2 = Err Then
Stop
Else
MsgBox ("Echec de l'ouverture " + SessName0 + ". Interruption de la simulation")
Stop
End If
End If
If Not Sess0.Visible Then Sess0.Visible = True
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)

Dim Sess1 As Object
SessName1$ = "TN3270_E.EDP"

Set Sess1 = Sessions.Item(SessName1$)
If Sess1 Is Nothing Then
Err = MsgBox(SessName1 + " n'est pas ouvert. Souhaitez-vous l'ouvrir ?", 1)
If 1 = Err Then
Err = 0
Set Sess1 = Sessions.Open(SessName1)
If Err Then
MsgBox ("Echec de l'ouverture " + SessName1 + ". Interruption de la simulation")
Stop
End If
ElseIf 2 = Err Then
Stop
Else
MsgBox ("Echec de l'ouverture " + SessName1 + ". Interruption de la simulation")
Stop
End If
End If
If Not Sess1.Visible Then Sess1.Visible = True
Sess1.Screen.WaitHostQuiet (g_HostSettleTime)

Dim Sess2 As Object
SessName2$ = "TN3270_B.EDP"

Set Sess2 = Sessions.Item(SessName2$)
If Sess2 Is Nothing Then
Err = MsgBox(SessName2 + " n'est pas ouvert. Souhaitez-vous l'ouvrir ?", 1)
If 1 = Err Then
Err = 0
Set Sess2 = Sessions.Open(SessName2)
If Err Then
MsgBox ("Echec de l'ouverture " + SessName2 + ". Interruption de la simulation")
Stop
End If
ElseIf 2 = Err Then
Stop
Else
MsgBox ("Echec de l'ouverture " + SessName2 + ". Interruption de la simulation")
Stop
End If
End If
If Not Sess2.Visible Then Sess2.Visible = True
Sess2.Screen.WaitHostQuiet (g_HostSettleTime)

Dim Sess3 As Object
SessName3$ = "TN3270_D.EDP"

Set Sess3 = Sessions.Item(SessName3$)
If Sess3 Is Nothing Then
Err = MsgBox(SessName3 + " n'est pas ouvert. Souhaitez-vous l'ouvrir ?", 1)
If 1 = Err Then
Err = 0
Set Sess3 = Sessions.Open(SessName3)
If Err Then
MsgBox ("Echec de l'ouverture " + SessName3 + ". Interruption de la simulation")
Stop
End If
ElseIf 2 = Err Then
Stop
Else
MsgBox ("Echec de l'ouverture " + SessName3 + ". Interruption de la simulation")
Stop
End If
End If
If Not Sess3.Visible Then Sess3.Visible = True
Sess3.Screen.WaitHostQuiet (g_HostSettleTime)

Dim Sess4 As Object
SessName4$ = "TN3270_C.EDP"

Set Sess4 = Sessions.Item(SessName4$)
If Sess4 Is Nothing Then
Err = MsgBox(SessName4 + " n'est pas ouvert. Souhaitez-vous l'ouvrir ?", 1)
If 1 = Err Then
Err = 0
Set Sess4 = Sessions.Open(SessName4)
If Err Then
MsgBox ("Echec de l'ouverture " + SessName4 + ". Interruption de la simulation")
Stop
End If
ElseIf 2 = Err Then
Stop
Else
MsgBox ("Echec de l'ouverture " + SessName4 + ". Interruption de la simulation")
Stop
End If
End If
If Not Sess4.Visible Then Sess4.Visible = True
Sess4.Screen.WaitHostQuiet (g_HostSettleTime)

' Cette section du code contient les événements enregistrés.
Sess2.Screen.SendKeys ("<Enter><Pf10><Tab><Tab>")
Sess2.Screen.WaitHostQuiet (g_HostSettleTime)
Sess2.Screen.SendKeys (NO_IMMA)
Sess2.Screen.WaitHostQuiet (g_HostSettleTime)
Sess2.Screen.SendKeys ("<Enter><Tab>")

Sess2.Screen.WaitHostQuiet (g_HostSettleTime)
Sess2.Screen.SendKeys (NO_COMPTE)
Sess2.Screen.SendKeys ("<Enter><Enter><Enter>")

Sess2.Screen.WaitHostQuiet (g_HostSettleTime)
Sess2.Screen.SendKeys (KMS)
Sess2.Screen.SendKeys ("<Enter><Enter><Enter>")

Sess2.Screen.WaitHostQuiet (g_HostSettleTime)
Sess2.Screen.SendKeys (code1)

Sess2.Screen.WaitHostQuiet (g_HostSettleTime)
Sess2.Screen.SendKeys (code2)

Sess2.Screen.WaitHostQuiet (g_HostSettleTime)
Sess2.Screen.SendKeys (code3)

Sess2.Screen.WaitHostQuiet (g_HostSettleTime)
Sess2.Screen.SendKeys (code4)

Sess2.Screen.WaitHostQuiet (g_HostSettleTime)
Sess2.Screen.SendKeys (code5)


Sess2.Screen.SendKeys ("<Enter><Enter>")


System.TimeoutValue = OldSystemTimeout
End Sub


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top