How to Print certain sheets in a workbook into PDF [duplicate]












1
















This question already has an answer here:




  • Save multiple sheets to .pdf

    4 answers




I want to convert certain excel sheets into PDF, the following sheets are "COVER","SCOPE","SUMMARY", "Updated Hours EST" and "RATES".



The following code below is for physically printing the certain sheets in the file. So how would you go about converting the code below into PDF print instead.



Private Sub PrintPDF_Button_Click()

Dim WB As Workbook
Dim arr As Variant
Dim i As Long
Const mySheets As String = "COVER,SCOPE,SUMMARY, Updated Hours EST, RATES"

Set WB = ActiveWorkbook

arr = Split(mySheets, ",")
For i = LBound(arr) To UBound(arr)
WB.Sheets(arr(i)).PrintOut
Next i
End Sub









share|improve this question













marked as duplicate by Tim Williams excel
Users with the  excel badge can single-handedly close excel questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 '18 at 19:52


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • what about using a PDF printer for the call to .PrintOut?

    – Maksim
    Nov 19 '18 at 16:38











  • what would be the command for PDF printer because not all the users using the workbook will have PDF printer as a default choice.

    – Sharath Chander
    Nov 19 '18 at 16:44











  • Well then If you have a version above 2010, you could make a copy of your workbook, remove all unwanted sheets and save it directly "as pdf".

    – Maksim
    Nov 19 '18 at 16:51













  • I want to automate it, not doing that everytime I update a field within one of those sheets.

    – Sharath Chander
    Nov 19 '18 at 17:07








  • 1





    stackoverflow.com/questions/14404650/…

    – Tim Williams
    Nov 19 '18 at 18:47
















1
















This question already has an answer here:




  • Save multiple sheets to .pdf

    4 answers




I want to convert certain excel sheets into PDF, the following sheets are "COVER","SCOPE","SUMMARY", "Updated Hours EST" and "RATES".



The following code below is for physically printing the certain sheets in the file. So how would you go about converting the code below into PDF print instead.



Private Sub PrintPDF_Button_Click()

Dim WB As Workbook
Dim arr As Variant
Dim i As Long
Const mySheets As String = "COVER,SCOPE,SUMMARY, Updated Hours EST, RATES"

Set WB = ActiveWorkbook

arr = Split(mySheets, ",")
For i = LBound(arr) To UBound(arr)
WB.Sheets(arr(i)).PrintOut
Next i
End Sub









share|improve this question













marked as duplicate by Tim Williams excel
Users with the  excel badge can single-handedly close excel questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 '18 at 19:52


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • what about using a PDF printer for the call to .PrintOut?

    – Maksim
    Nov 19 '18 at 16:38











  • what would be the command for PDF printer because not all the users using the workbook will have PDF printer as a default choice.

    – Sharath Chander
    Nov 19 '18 at 16:44











  • Well then If you have a version above 2010, you could make a copy of your workbook, remove all unwanted sheets and save it directly "as pdf".

    – Maksim
    Nov 19 '18 at 16:51













  • I want to automate it, not doing that everytime I update a field within one of those sheets.

    – Sharath Chander
    Nov 19 '18 at 17:07








  • 1





    stackoverflow.com/questions/14404650/…

    – Tim Williams
    Nov 19 '18 at 18:47














1












1








1









This question already has an answer here:




  • Save multiple sheets to .pdf

    4 answers




I want to convert certain excel sheets into PDF, the following sheets are "COVER","SCOPE","SUMMARY", "Updated Hours EST" and "RATES".



The following code below is for physically printing the certain sheets in the file. So how would you go about converting the code below into PDF print instead.



Private Sub PrintPDF_Button_Click()

Dim WB As Workbook
Dim arr As Variant
Dim i As Long
Const mySheets As String = "COVER,SCOPE,SUMMARY, Updated Hours EST, RATES"

Set WB = ActiveWorkbook

arr = Split(mySheets, ",")
For i = LBound(arr) To UBound(arr)
WB.Sheets(arr(i)).PrintOut
Next i
End Sub









share|improve this question















This question already has an answer here:




  • Save multiple sheets to .pdf

    4 answers




I want to convert certain excel sheets into PDF, the following sheets are "COVER","SCOPE","SUMMARY", "Updated Hours EST" and "RATES".



The following code below is for physically printing the certain sheets in the file. So how would you go about converting the code below into PDF print instead.



Private Sub PrintPDF_Button_Click()

Dim WB As Workbook
Dim arr As Variant
Dim i As Long
Const mySheets As String = "COVER,SCOPE,SUMMARY, Updated Hours EST, RATES"

Set WB = ActiveWorkbook

arr = Split(mySheets, ",")
For i = LBound(arr) To UBound(arr)
WB.Sheets(arr(i)).PrintOut
Next i
End Sub




This question already has an answer here:




  • Save multiple sheets to .pdf

    4 answers








excel vba pdf printing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 16:31









Sharath ChanderSharath Chander

376




376




marked as duplicate by Tim Williams excel
Users with the  excel badge can single-handedly close excel questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 '18 at 19:52


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Tim Williams excel
Users with the  excel badge can single-handedly close excel questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 '18 at 19:52


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • what about using a PDF printer for the call to .PrintOut?

    – Maksim
    Nov 19 '18 at 16:38











  • what would be the command for PDF printer because not all the users using the workbook will have PDF printer as a default choice.

    – Sharath Chander
    Nov 19 '18 at 16:44











  • Well then If you have a version above 2010, you could make a copy of your workbook, remove all unwanted sheets and save it directly "as pdf".

    – Maksim
    Nov 19 '18 at 16:51













  • I want to automate it, not doing that everytime I update a field within one of those sheets.

    – Sharath Chander
    Nov 19 '18 at 17:07








  • 1





    stackoverflow.com/questions/14404650/…

    – Tim Williams
    Nov 19 '18 at 18:47



















  • what about using a PDF printer for the call to .PrintOut?

    – Maksim
    Nov 19 '18 at 16:38











  • what would be the command for PDF printer because not all the users using the workbook will have PDF printer as a default choice.

    – Sharath Chander
    Nov 19 '18 at 16:44











  • Well then If you have a version above 2010, you could make a copy of your workbook, remove all unwanted sheets and save it directly "as pdf".

    – Maksim
    Nov 19 '18 at 16:51













  • I want to automate it, not doing that everytime I update a field within one of those sheets.

    – Sharath Chander
    Nov 19 '18 at 17:07








  • 1





    stackoverflow.com/questions/14404650/…

    – Tim Williams
    Nov 19 '18 at 18:47

















what about using a PDF printer for the call to .PrintOut?

– Maksim
Nov 19 '18 at 16:38





what about using a PDF printer for the call to .PrintOut?

– Maksim
Nov 19 '18 at 16:38













what would be the command for PDF printer because not all the users using the workbook will have PDF printer as a default choice.

– Sharath Chander
Nov 19 '18 at 16:44





what would be the command for PDF printer because not all the users using the workbook will have PDF printer as a default choice.

– Sharath Chander
Nov 19 '18 at 16:44













Well then If you have a version above 2010, you could make a copy of your workbook, remove all unwanted sheets and save it directly "as pdf".

– Maksim
Nov 19 '18 at 16:51







Well then If you have a version above 2010, you could make a copy of your workbook, remove all unwanted sheets and save it directly "as pdf".

– Maksim
Nov 19 '18 at 16:51















I want to automate it, not doing that everytime I update a field within one of those sheets.

– Sharath Chander
Nov 19 '18 at 17:07







I want to automate it, not doing that everytime I update a field within one of those sheets.

– Sharath Chander
Nov 19 '18 at 17:07






1




1





stackoverflow.com/questions/14404650/…

– Tim Williams
Nov 19 '18 at 18:47





stackoverflow.com/questions/14404650/…

– Tim Williams
Nov 19 '18 at 18:47












1 Answer
1






active

oldest

votes


















0














You can try seeing if the worksheet.ExportAsFixedFormat method will do what you need it to do:



Const savePath$ = "C:........"

Dim i As Long, arr()
arr = Array("COVER", "SCOPE", "SUMMARY", "Updated Hours EST", "RATES")

For i = 0 To UBound(arr)

ThisWorkbook.Worksheets(arr(i)).ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=savePath & arr(i) & ".pdf", quality:=xlQualityStandard, _
openafterpublish:=False

Next


Just make sure that you update savePath string to your file location - otherwise you can omit that altogether and go for something that will prompt a saveas dialog box if that is your preference.





Further reading on this method:




Worksheet.ExportAsFixedFormat method (Source: MS Docs)



Exports to a file of the specified format.



Syntax



expression.ExportAsFixedFormat( _Type_ , _Filename_ , _Quality_ , _IncludeDocProperties_ , _IgnorePrintAreas_ , _From_ , _To_ , _OpenAfterPublish_ ) (Definitions)



Remarks



This method also supports initializing an add-in to export a file to a fixed-format file. For example, Excel will perform file format conversion if the converters are present. The conversion is usually initiated by the user.







share|improve this answer


























  • Thanks it worked, but at the moment the pdf is separate for each sheet and so it there is a way to combine those sheets into one big PDF file?

    – Sharath Chander
    Nov 19 '18 at 18:33






  • 1





    stackoverflow.com/questions/14404650/…

    – Tim Williams
    Nov 19 '18 at 18:46











  • @TimWilliams You can go ahead and close as dupe

    – K.Dᴀᴠɪs
    Nov 19 '18 at 18:58


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You can try seeing if the worksheet.ExportAsFixedFormat method will do what you need it to do:



Const savePath$ = "C:........"

Dim i As Long, arr()
arr = Array("COVER", "SCOPE", "SUMMARY", "Updated Hours EST", "RATES")

For i = 0 To UBound(arr)

ThisWorkbook.Worksheets(arr(i)).ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=savePath & arr(i) & ".pdf", quality:=xlQualityStandard, _
openafterpublish:=False

Next


Just make sure that you update savePath string to your file location - otherwise you can omit that altogether and go for something that will prompt a saveas dialog box if that is your preference.





Further reading on this method:




Worksheet.ExportAsFixedFormat method (Source: MS Docs)



Exports to a file of the specified format.



Syntax



expression.ExportAsFixedFormat( _Type_ , _Filename_ , _Quality_ , _IncludeDocProperties_ , _IgnorePrintAreas_ , _From_ , _To_ , _OpenAfterPublish_ ) (Definitions)



Remarks



This method also supports initializing an add-in to export a file to a fixed-format file. For example, Excel will perform file format conversion if the converters are present. The conversion is usually initiated by the user.







share|improve this answer


























  • Thanks it worked, but at the moment the pdf is separate for each sheet and so it there is a way to combine those sheets into one big PDF file?

    – Sharath Chander
    Nov 19 '18 at 18:33






  • 1





    stackoverflow.com/questions/14404650/…

    – Tim Williams
    Nov 19 '18 at 18:46











  • @TimWilliams You can go ahead and close as dupe

    – K.Dᴀᴠɪs
    Nov 19 '18 at 18:58
















0














You can try seeing if the worksheet.ExportAsFixedFormat method will do what you need it to do:



Const savePath$ = "C:........"

Dim i As Long, arr()
arr = Array("COVER", "SCOPE", "SUMMARY", "Updated Hours EST", "RATES")

For i = 0 To UBound(arr)

ThisWorkbook.Worksheets(arr(i)).ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=savePath & arr(i) & ".pdf", quality:=xlQualityStandard, _
openafterpublish:=False

Next


Just make sure that you update savePath string to your file location - otherwise you can omit that altogether and go for something that will prompt a saveas dialog box if that is your preference.





Further reading on this method:




Worksheet.ExportAsFixedFormat method (Source: MS Docs)



Exports to a file of the specified format.



Syntax



expression.ExportAsFixedFormat( _Type_ , _Filename_ , _Quality_ , _IncludeDocProperties_ , _IgnorePrintAreas_ , _From_ , _To_ , _OpenAfterPublish_ ) (Definitions)



Remarks



This method also supports initializing an add-in to export a file to a fixed-format file. For example, Excel will perform file format conversion if the converters are present. The conversion is usually initiated by the user.







share|improve this answer


























  • Thanks it worked, but at the moment the pdf is separate for each sheet and so it there is a way to combine those sheets into one big PDF file?

    – Sharath Chander
    Nov 19 '18 at 18:33






  • 1





    stackoverflow.com/questions/14404650/…

    – Tim Williams
    Nov 19 '18 at 18:46











  • @TimWilliams You can go ahead and close as dupe

    – K.Dᴀᴠɪs
    Nov 19 '18 at 18:58














0












0








0







You can try seeing if the worksheet.ExportAsFixedFormat method will do what you need it to do:



Const savePath$ = "C:........"

Dim i As Long, arr()
arr = Array("COVER", "SCOPE", "SUMMARY", "Updated Hours EST", "RATES")

For i = 0 To UBound(arr)

ThisWorkbook.Worksheets(arr(i)).ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=savePath & arr(i) & ".pdf", quality:=xlQualityStandard, _
openafterpublish:=False

Next


Just make sure that you update savePath string to your file location - otherwise you can omit that altogether and go for something that will prompt a saveas dialog box if that is your preference.





Further reading on this method:




Worksheet.ExportAsFixedFormat method (Source: MS Docs)



Exports to a file of the specified format.



Syntax



expression.ExportAsFixedFormat( _Type_ , _Filename_ , _Quality_ , _IncludeDocProperties_ , _IgnorePrintAreas_ , _From_ , _To_ , _OpenAfterPublish_ ) (Definitions)



Remarks



This method also supports initializing an add-in to export a file to a fixed-format file. For example, Excel will perform file format conversion if the converters are present. The conversion is usually initiated by the user.







share|improve this answer















You can try seeing if the worksheet.ExportAsFixedFormat method will do what you need it to do:



Const savePath$ = "C:........"

Dim i As Long, arr()
arr = Array("COVER", "SCOPE", "SUMMARY", "Updated Hours EST", "RATES")

For i = 0 To UBound(arr)

ThisWorkbook.Worksheets(arr(i)).ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=savePath & arr(i) & ".pdf", quality:=xlQualityStandard, _
openafterpublish:=False

Next


Just make sure that you update savePath string to your file location - otherwise you can omit that altogether and go for something that will prompt a saveas dialog box if that is your preference.





Further reading on this method:




Worksheet.ExportAsFixedFormat method (Source: MS Docs)



Exports to a file of the specified format.



Syntax



expression.ExportAsFixedFormat( _Type_ , _Filename_ , _Quality_ , _IncludeDocProperties_ , _IgnorePrintAreas_ , _From_ , _To_ , _OpenAfterPublish_ ) (Definitions)



Remarks



This method also supports initializing an add-in to export a file to a fixed-format file. For example, Excel will perform file format conversion if the converters are present. The conversion is usually initiated by the user.








share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 '18 at 18:15

























answered Nov 19 '18 at 18:02









K.DᴀᴠɪsK.Dᴀᴠɪs

7,209112439




7,209112439













  • Thanks it worked, but at the moment the pdf is separate for each sheet and so it there is a way to combine those sheets into one big PDF file?

    – Sharath Chander
    Nov 19 '18 at 18:33






  • 1





    stackoverflow.com/questions/14404650/…

    – Tim Williams
    Nov 19 '18 at 18:46











  • @TimWilliams You can go ahead and close as dupe

    – K.Dᴀᴠɪs
    Nov 19 '18 at 18:58



















  • Thanks it worked, but at the moment the pdf is separate for each sheet and so it there is a way to combine those sheets into one big PDF file?

    – Sharath Chander
    Nov 19 '18 at 18:33






  • 1





    stackoverflow.com/questions/14404650/…

    – Tim Williams
    Nov 19 '18 at 18:46











  • @TimWilliams You can go ahead and close as dupe

    – K.Dᴀᴠɪs
    Nov 19 '18 at 18:58

















Thanks it worked, but at the moment the pdf is separate for each sheet and so it there is a way to combine those sheets into one big PDF file?

– Sharath Chander
Nov 19 '18 at 18:33





Thanks it worked, but at the moment the pdf is separate for each sheet and so it there is a way to combine those sheets into one big PDF file?

– Sharath Chander
Nov 19 '18 at 18:33




1




1





stackoverflow.com/questions/14404650/…

– Tim Williams
Nov 19 '18 at 18:46





stackoverflow.com/questions/14404650/…

– Tim Williams
Nov 19 '18 at 18:46













@TimWilliams You can go ahead and close as dupe

– K.Dᴀᴠɪs
Nov 19 '18 at 18:58





@TimWilliams You can go ahead and close as dupe

– K.Dᴀᴠɪs
Nov 19 '18 at 18:58



Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)