Convert a Specific Sheet to PDF but with Special Criteria

Cagey93

New Member
Joined
Apr 17, 2019
Messages
34
Hello,

Ill try an explain this as best I can.

I need to open a workbook remotely called "Main Monthly File May2019_pre sonia.xlsx" select the sheet "Covered Bonds Movements" then set the print range "A1:H130" and then convert that area to PDF but the kicker is the PDF has to be 1 A4 sheet with two pages on it if that makes sense. So the top half of the print area on the left and the bottom half on the right.


I cannot seem to get VBA to do this but there has to be away. I have put the basic code below which works fine it just doesn't put both halves side by side.
I know this isn't using the printer but there must be away to do it via this method?


Code:
[FONT='inherit']<code class="rz6fp9-7 jYpcYF" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">Dim filepath1 As String</code>[/FONT]
[FONT='inherit']<code class="rz6fp9-7 jYpcYF" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">Dim filename1 As String</code>[/FONT]
[FONT='inherit']<code class="rz6fp9-7 jYpcYF" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">Dim outputfile1 As String</code>[/FONT]
[FONT='inherit']<code class="rz6fp9-7 jYpcYF" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">Dim filepath8 As String</code>[/FONT]
[FONT='inherit']<code class="rz6fp9-7 jYpcYF" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">Dim filename8 As String</code>[/FONT]
[FONT='inherit']<code class="rz6fp9-7 jYpcYF" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">Dim outputfile8 As String</code>[/FONT]
[FONT='inherit']
[/FONT]
[FONT='inherit']<code class="rz6fp9-7 jYpcYF" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">filepath8 = Range("C14")</code>[/FONT]
[FONT='inherit']<code class="rz6fp9-7 jYpcYF" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">filename8 = Range("F14")</code>[/FONT]
[FONT='inherit']<code class="rz6fp9-7 jYpcYF" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">outputfile8 = Range("F14")</code>[/FONT]
[FONT='inherit']
[/FONT]
[FONT='inherit']<code class="rz6fp9-7 jYpcYF" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">Application.AskToUpdateLinks = False</code>[/FONT]
[FONT='inherit']<code class="rz6fp9-7 jYpcYF" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">Application.DisplayAlerts = False</code>[/FONT]
[FONT='inherit'][URL="https://workbooks.open/"]<code class="rz6fp9-7 jYpcYF" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">Workbooks.Open</code>[/URL] <code class="rz6fp9-7 jYpcYF" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">(filepath8)</code>[/FONT]
[FONT='inherit']<code class="rz6fp9-7 jYpcYF" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">Sheets("Covered Bonds Movements").Range("A1:H131").ExportAsFixedFormat Type:=xlTypePDF, _</code>[/FONT]
[FONT='inherit']<code class="rz6fp9-7 jYpcYF" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">Filename:=(outputfile8)</code>[/FONT]
[FONT='inherit']<code class="rz6fp9-7 jYpcYF" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">ActiveWindow.Close</code>[/FONT]
[FONT='inherit']
[/FONT]
[FONT='inherit']<code class="rz6fp9-7 jYpcYF" style="margin: 0px 2px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: 13px; line-height: 20px; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; vertical-align: baseline; background: rgba(238, 238, 238, 0.8); color: rgb(255, 0, 109); max-width: 100%; overflow: auto;">End Sub</code>[/FONT]
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Most machines come with some kind of PDF printer software, nowdays - such as "Microsoft Print to PDF." Not sure whether this ships with Windows, or when you load one of the Adobe applications, but it's always there on the machines that I've used.

If you have this on your machine(s), couldn't you just write a bit of VBA to temporarily change to this printer (just been helping on another post, on this subject, funnily enough) then print to it, specifying the destination, and specifying printing 2 pages per sheet, having split your worksheet area into 2 pages?
 
Upvote 0
I do have Adobe PDF printer on the machines thats fine but when I have tried the .TwoPagesOnOne = True the script just falls over.
 
Upvote 0

Forum statistics

Threads
1,214,385
Messages
6,119,205
Members
448,874
Latest member
Lancelots

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top