Script PDFCreator

e040098k Messages postés 28 Date d'inscription dimanche 4 février 2007 Statut Membre Dernière intervention 4 mai 2007 - 4 avril 2007 à 09:07
e040098k Messages postés 28 Date d'inscription dimanche 4 février 2007 Statut Membre Dernière intervention 4 mai 2007 - 11 avril 2007 à 16:09
Bonjour, Je suis actuellement en stage dans un cabinet comptable, et je viens d'installer PDFCreator. Je remarque que l'on peut lui faire executer des scripts après l'enregistrement(action après l'enregistrement).

Je crois que c'est codé en VBscript mais je ne suis pas sur. Exemple qui ouvre un popup

' PopUpMessage script
' Part of PDFCreator
' License: GPL
' Homepage: http://www.sf.net/projects/pdfcreator
' Version: 1.1.0.0
' Date: September, 1. 2005
' Author: Frank Heindörfer

Option Explicit

Const AppTitle = "PDFCreator - PopUpMessage"
Const SecondsToWait = 5

Dim objArgs, WshShell

Set objArgs = WScript.Arguments

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

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

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

J'aimerais pouvoir ouvrir une MsgBox qui me propose d'effacer le fichier original (.doc)

Quelqu'un peut-il m'aider ? Je commence à désespérer !! Merci beaucoup

4 réponses

mortalino Messages postés 6786 Date d'inscription vendredi 16 décembre 2005 Statut Membre Dernière intervention 21 décembre 2011 18
4 avril 2007 à 10:54
Salut,

je ne fais pas de vbscript, cependant je me permet de remettre en forme ton code, car c'est difficilement lisible :

Option Explicit

Const AppTitle = "PDFCreator - PopUpMessage"
Const SecondsToWait = 5

Dim objArgs, WshShell
Set objArgs = WScript.Arguments

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

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Popup "Le pdf à été crée" & vbcrlf & vbcrlf & _ "Filename:" & vbtab & vbtab & objArgs(0) & vbcrlf, SecondsToWait, AppTitle, 0

@++

<hr width="100%" size="2" />
  --Mortalino--
Le mystérieux chevalier, "Provençal, le Gaulois"
/DIV>
0
e040098k Messages postés 28 Date d'inscription dimanche 4 février 2007 Statut Membre Dernière intervention 4 mai 2007
4 avril 2007 à 15:16
Merci beaucoup mortalino
0
e040098k Messages postés 28 Date d'inscription dimanche 4 février 2007 Statut Membre Dernière intervention 4 mai 2007
11 avril 2007 à 10:06
J'ai avancé un peu dans mon initiation a VB script, je cherche toujours à 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 (désolé pour la mise en page je pense que cela viens d'opéra) :

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
0
e040098k Messages postés 28 Date d'inscription dimanche 4 février 2007 Statut Membre Dernière intervention 4 mai 2007
11 avril 2007 à 16:09
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
Rejoignez-nous