Macro qui marche seulement en mode debug
Bonjour,
J'ai écrit la macro suivante qui crée un fichier pdf (par l'intermédiaire de PDFCreator en mode autosave c'est-à-dire sans l'intervention de l'utilisateur). Le fichier pdf a le même nom que la feuille Excel et est sauvegardé dans le même répertoire que la feuille Excel.
Le problème est que la macro marche quand je suis en mode édition debug en lançant la macro pas à pas. Par contre en mode normal, elle ne marche pas.:?
Pouvez-vous m'aider à régler ceci ?
Merci
Nicolas
Voici la macro en question:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Sub ToPdf()
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
NomExcel = ActiveWorkbook.Name
NomPdf = Left(NomExcel, Len(NomExcel) - 4)
With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + vbOKOnly, "PrtPDFCreator"
Exit Sub
End If
.cOption("UseAutosave") = 1
.cOption("UseAutisaveDirectory") = 1
.cOption("AutosaveDirectory") = ActiveWorkbook.Path
.cOption("AutosaveFilename") = NomPdf
.cOption("AutosaveFormat") = 0 ' 0 = pdf
.cClearCache
End With
ActiveWorkbook.Sheets("TABLE").PrintOut Copies:=1, ActivePrinter:="PDFCreator"
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Sleep 1000
Loop
With pdfjob
.cDefaultprinter = DefaultPrinter
.cClearCache
.cClose
End With
Set pdfjob = Nothing
End Sub |
Personne n'a d'idée sur la question ?
Je ne comprends vraiment pas pourquoi cela ne marche pas en mode normal. Quelqu'un pourrait au moins essayer la macro en modes debug et normal pour me confirmer qu'il y a un problème !! Peut-être le problème vient de ma configuration système.
Nicolas