Script PDF creator

Pierro -  
 Pierro -
J'ai avancé un peu dans mon initiation a VB script, je cherche à supprimer un fichier après la création d'un pdf.
J'ai réussi à programmer ma MsgBox mais lorsque j'éxécute mon scrip, le fichier n'est pas supprimer !

Quelqu'un sait-il résoudre mon problème ?

voila mon code :

Option Explicit

Const AppTitle = "PDFCreator - MSAgent"
Const TextToSpeech = "Le fichier pdf à été créé ! Pensez à supprimer le fichier original"
Const AgentName = "Merlin"

Dim objAgent, objCharacter, c, HideID, LastID

LastID = 0

On Error Resume Next

Set objAgent = CreateObject("Agent.Control.2")
If Err.Number <> 0 Then
MsgBox "This script needs MS SAPI runtime." & vbcrlf & vbcrlf & _
"For more informations use this link." & vbcrlf & _
"http://www.microsoft.com/MSAGENT/downloads/user.asp#sapi" & vbcrlf & vbcrlf & _
Err.Number & " " & Err.Description, vbCritical, AppTitle

WScript.Quit
End If

WScript.ConnectObject objAgent, "Agent_"

objAgent.Connected = TRUE
objAgent.Characters.Load AgentName, AgentName & ".acs"
If Err.Number <> 0 Then
MsgBox "Try to load the agent character file: " & AgentName & ".acs" & vbcrlf & vbcrlf & _
"For more informations use this link." & vbcrlf & _
"http://www.microsoft.com/MSAGENT/downloads/user.asp#character" & vbcrlf & vbcrlf & _
Err.Number & " " & Err.Description, vbCritical, AppTitle
WScript.Quit
End If

Set objCharacter = objAgent.Characters.Character(AgentName)

With objCharacter
.Show
.LanguageID = &H0409 ' English
.Play "GetAttention"
.Speak TextToSpeech
Set HideID = .Hide
End With

c = 150 ' Don't wait more than 15 seconds
Do While (c > 0) and (LastID <> HideID)
c = c -1
Wscript.Sleep 100
Loop

Public Sub Agent_RequestComplete(ByVal Request)
LastID = Request
If MsgBox("Voulez vous supprimer le fichier source ?",vbQuestion + vbYesNo + vbSystemModal + 0,"Suppression du fichier source") = vbYes Then
'déclaration file system object
Dim fso

'instanciation
Set FSO = CreateObject("Scripting.FileSystemObject")
'Suppression du fichier
Set Ftxt = fso.GetFile("C:\Documents and Settings\stagiaire1\Bureau\Nouveau_Document_texte.txt") 'Fichier origine
Ftxt.delete
Else Wscript.Quit
End if
End Sub
Configuration: Windows XP
Opera 9.10

1 réponse

  1. Pierro
     
    Pour terminer mon petit script, je doit récupérer le nom du fichier pdf que j'ai créer (monfichier.pdf) afin de d'avoir le nom du fichier source (monfichier.doc).

    J'ai réussi à retrouver ce nom grace à objArgs. Mais cela ne me permet que de l'afficher dans une MsgBox, je n'arrive pas à le réutiliser dans la routine de suppression ! Il me faut récupérer le nom du fichier auquel je concaterais ".doc"

    Merci pour votre aide !!

    Code :
    Option Explicit
    'déclaration file system object
    Dim fso
    Dim Ftxt
    Dim objArgs, WshShell

    Set objArgs = WScript.Arguments

    If objArgs.Count = 0 Then
    MsgBox "This script needs a parameter!", vbExclamation
    WScript.Quit
    End If

    Set WshShell = WScript.CreateObject("WScript.Shell")

    WshShell.Popup "Le pdf à été crée" & vbcrlf & vbcrlf & _
    "Filename:" & vbtab & objArgs(0) & vbcrlf, 0

    If MsgBox("Voulez vous supprimer le fichier source ?",vbQuestion + vbYesNo + vbSystemModal + 0,"Suppression du fichier source") = vbYes Then

    'instanciation
    Set FSO = CreateObject("Scripting.FileSystemObject")
    'Suppression du fichier
    Set Ftxt = fso.GetFile("C:\Documents and Settings\stagiaire1\Bureau\Nouveau Document texte.txt") 'Fichier origine
    Ftxt.delete
    Else Wscript.Quit
    End if
    0