Option Explicit
Dim semaine As String
Private Sub CommandButton2_Click()
semaine = Range("AZ10") 'a adapter
dossier 'création dossier
chemsave = "C:\chemin repertoire\" & semaine & "\"""
End Sub
Sub ToPdf()
Dim chemsave As String
chemsave = "C:\chemin dossier destination\" 'chemin destination
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")
NomExcel = ThisWorkbook.Name
NomPdf = Left(NomExcel, Len(NomExcel) - 4) & ".pdf"
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") = chemsave 'chemin destination
.cOption("AutosaveFilename") = NomPdf
.cOption("AutosaveFormat") = 0
.cClearCache
End With
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=32766, Copies:=1, ActivePrinter:="PDFCreator" 'on imprime la feuille active
'ThisWorkbook.PrintOut Copies:=1, ActivePrinter:="PDFCreator"
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
With pdfjob
.cDefaultprinter = DefaultPrinter
.cClearCache
.cClose
End With
Set pdfjob = Nothing
MsgBox "Votre PDF se trouve à cet emplacement: " & chemsave, vbInformation, "Convertir en PDF"
End Sub
Private Type PRINTER_INFO_5
pPrinterName As String
pPortName As String
Attributes As Long
DeviceNotSelectedTimeout As Long
TransmissionRetryTimeout As Long
End Type
Private Declare Function EnumPrintersA Lib "Winspool.drv" _
(ByVal flags As Long, ByVal name As String, ByVal Level As Long, _
pPrinterEnum As Long, ByVal cdBuf As Long, _
pcbNeeded As Long, pcReturned As Long) As Long
Private Declare Function lstrlenA Lib "Kernel32" _
(ByVal lpString As Any) As Long
Private Declare Function lstrcpyA Lib "Kernel32" _
(ByVal lpString1 As String, ByVal lpString2 As Long) As Long
Sub Test()
Dim PrinterEnum() As Long, Impr() As String
Dim Needed As Long, Returned As Long, I As Integer
EnumPrintersA 2, vbNullString, 5, 0, 0, Needed, 0
ReDim PrinterEnum(Needed / 4)
EnumPrintersA 2, vbNullString, 5, PrinterEnum(0), _
Needed, Needed, Returned
ReDim Impr(1 To Returned)
For I = 1 To Returned
Impr(I) = Space$(lstrlenA(PrinterEnum(I * 5 - 5)))
lstrcpyA Impr(I), PrinterEnum(I * 5 - 5)
Next I
Range("A1").Resize(Returned) = WorksheetFunction.Transpose(Impr)
Columns(1).AutoFit
End Sub
Private Sub ListBox1_Click()
Range("B1") = ListBox1.Value
Range("C1") = "1"
End Sub
Private Sub UserForm_Initialize()
Sheets("Feuil2").Select
Test
ListBox1.RowSource = "A1:A10" 'affiche les imprimantes dans la listBoxEnd Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If Range("C1") = "" Then
MsgBox "Vous devez sélectionner votre imprimante par défaut.", vbInformation, "Imprimantes"
If CloseMode = 0 Then Cancel = True
Else
Sheets("Feuil1").Select
End If
End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub UserForm_Initialize()
Listerfeuille
ComboBox1.ListIndex = 0
ComboBox1.RemoveItem (2)' a adapter
ComboBox1.RemoveItem (5)
End Sub
Private Sub UserForm_Initialize()
Listerfeuille
ComboBox1.ListIndex = 0
ComboBox1.RemoveItem (0)' a adapter
ComboBox1.RemoveItem (1)
End Sub
Private Sub UserForm_Initialize()
Listerfeuille
ComboBox1.RemoveItem (0)' a adapter
ComboBox1.RemoveItem (1)
ComboBox1.ListIndex = 2
End Sub
Option Explicit
Dim semaine As String
Private Sub CommandButton2_Click()
semaine = Range("A1") 'a adapter
dossier 'création dossier
chemsave = "C:\chemin repertoire\" & semaine & "\"
End Sub
Sub dossier()
If Len(Dir("C:\chemin repertoire\" & semaine, vbDirectory)) = 0 Then 'chemin a adapter
MkDir "C:\chemin repertoire\" & semaine
End If
End Sub
Option Explicit
Public chemsave As String
Private Sub Workbook_Open()
CreateBO
UserForm1.Show
End Sub
Option Explicit
Dim semaine As String
Private Sub CommandButton2_Click()
semaine = Range("AZ10") 'a adapter
dossier 'création dossier
chemsave = "C:\chemin repertoire\" & semaine & "\"
End Sub
Option Explicit
Public chemsave As String