petropatrick
Gebruiker
- Lid geworden
- 14 jan 2014
- Berichten
- 9
Goedenmorgen,
ik heb een vraagje ik ben nu al een tijdje bezig om mijn rapport compleet te maken.
ik heb diverse knoppen gemaakt met daaronder een macro of vba code die ik met behulp van dit forum heb gemaakt.
Nu zit ik met een probleempje ik heb er een knop bij gemaakt die van de sheets die op dat moment in de onderbalk staan 1 pdf moet maken maar hij maakt van alle sheets aparte pdfjes.
hoe kan ik dat veranderen?
en mijn tweede vraag is:hoe kan ik met de knop opslaan als die ik ook gemaakt heb de file opslaan in een vaste map?
de code voor het opslaan als 1 pdf:
Sub Copy_Every_Sheet_To_PDF()
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim sh As Worksheet
Dim DateString As String
Dim FolderName As String
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
'Copy every sheet from the workbook with this macro
Set Sourcewb = ThisWorkbook
'Create new folder to save the new files in
DateString = Format(Now, "yyyy-mm-dd hh-mm-ss")
FolderName = Sourcewb.Path & "\" & Sourcewb.Name & " " & DateString
MkDir FolderName
'Publish every visible worksheet with data
For Each sh In Sourcewb.Worksheets
'If the sheet is visible then copy it to a new workbook
If sh.Visible = -1 And sh.UsedRange.Cells.Count > 1 Then
'Publish worksheet to pdf
On Error Resume Next
sh.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=FolderName _
& "\" & sh.Name & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
On Error GoTo 0
End If
GoToNextSheet:
Next sh
MsgBox "You can find the files in " & FolderName
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With
End Sub
ik heb een vraagje ik ben nu al een tijdje bezig om mijn rapport compleet te maken.
ik heb diverse knoppen gemaakt met daaronder een macro of vba code die ik met behulp van dit forum heb gemaakt.
Nu zit ik met een probleempje ik heb er een knop bij gemaakt die van de sheets die op dat moment in de onderbalk staan 1 pdf moet maken maar hij maakt van alle sheets aparte pdfjes.
hoe kan ik dat veranderen?
en mijn tweede vraag is:hoe kan ik met de knop opslaan als die ik ook gemaakt heb de file opslaan in een vaste map?
de code voor het opslaan als 1 pdf:
Sub Copy_Every_Sheet_To_PDF()
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim sh As Worksheet
Dim DateString As String
Dim FolderName As String
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
'Copy every sheet from the workbook with this macro
Set Sourcewb = ThisWorkbook
'Create new folder to save the new files in
DateString = Format(Now, "yyyy-mm-dd hh-mm-ss")
FolderName = Sourcewb.Path & "\" & Sourcewb.Name & " " & DateString
MkDir FolderName
'Publish every visible worksheet with data
For Each sh In Sourcewb.Worksheets
'If the sheet is visible then copy it to a new workbook
If sh.Visible = -1 And sh.UsedRange.Cells.Count > 1 Then
'Publish worksheet to pdf
On Error Resume Next
sh.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=FolderName _
& "\" & sh.Name & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
On Error GoTo 0
End If
GoToNextSheet:
Next sh
MsgBox "You can find the files in " & FolderName
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With
End Sub