VBA for Excel (365), how to print to PDF, while scaling to fit all columns to a single page wide?

%3CLINGO-SUB%20id%3D%22lingo-sub-1767437%22%20slang%3D%22en-US%22%3EVBA%20for%20Excel%20(365)%2C%20how%20to%20print%20to%20PDF%2C%20while%20scaling%20to%20fit%20all%20columns%20to%20a%20single%20page%20wide%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1767437%22%20slang%3D%22en-US%22%3E%3CP%3EHello.%20Using%20VBA%20for%20Excel%20(Office365)%2C%20how%20can%20I%20print%20an%20Excel%20worksheet%20to%20PDF%2C%20while%20scaling%20to%20fit%20all%20columns%20to%20a%20single%20page%20wide%3F%20In%20my%20VBA%20script%2C%20I%20have%20already%20set%3A%20%60FitToPagesWide%20%3D%201%60.%20Here%20is%20more%20information.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20the%20past%20few%20years%20I've%20used%20Office%202013%2C%20and%20with%20it%2C%20a%20particular%20VBA%20for%20Excel%20script%20which%20would%20print%20a%20worksheet%20to%20PDF%2C%20while%20scaling%20to%20fit%20all%20columns%20to%20a%20single%20page%20wide.%20I%20recently%20updated%20to%20Office365%20and%20the%20same%20VBA%20script%20is%20now%20printing%20to%20PDF%2C%20but%20not%20scaling%20to%20fit%20all%20columns%20to%20a%20single%20page%20wide.%20Any%20ideas%20why%20that%20is%20occurring%20and%20how%20to%20resolve%20it%3F%3C%2FP%3E%3CP%3E%3CBR%20%2F%3ESee%20%3CA%20href%3D%22https%3A%2F%2Fpastebin.com%2FGrTuCffb%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ethis%20Pastebin%3C%2FA%3E%20for%20my%20VBA%20function.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1767437%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1767637%22%20slang%3D%22de-DE%22%3ESubject%3A%20VBA%20for%20Excel%20(365)%2C%20how%20to%20print%20to%20PDF%2C%20while%20scaling%20to%20fit%20all%20columns%20to%20a%20single%20page%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1767637%22%20slang%3D%22de-DE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F827436%22%20target%3D%22_blank%22%3E%40cagross%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22tlid-translation%20translation%22%3E%3CSPAN%20class%3D%22%22%3EAs%20far%20as%20I%20had%20to%20learn%20here%3C%2FSPAN%3E%3C%2FSPAN%3E...%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22tlid-translation%20translation%22%3E%3CSPAN%20class%3D%22%22%3E(This%20information%20without%20guarantee%2C%20I%20would%20be%20happy%20to%20be%20instructed%20if%20it%20could%20work.%3C%2FSPAN%3E%3CBR%20%2F%3E%20%3CSPAN%20class%3D%22%22%3EMS%20changes%2C%20develops%20and%20refines%20its%20products%20so%20well%20and%20quickly%20that%20you%20can%20hardly%20keep%20up%20with%20them.%3C%2FSPAN%3E%20%3CSPAN%3EThey%20are%20that%20good!%20%3C%2FSPAN%3E%3CSPAN%20class%3D%22%22%3E%3A).%3C%2FSPAN%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22tlid-translation%20translation%22%3EClick%20the%20Link%20for%20more%20info%20about%20this%20issue%2C%20Please%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EThis%20feature%20is%20not%20available%20in%20Excel%20for%20the%20web.%3C%2FP%3E%3CP%3EIf%20you%20have%20the%20Excel%20desktop%20application%2C%20you%20can%20use%20the%20Open%20in%20Excel%20button%20to%20open%20the%20workbook%20and%20scale%20the%20worksheet%20to%20fit%20data%20on%20one%20page.%3C%2FP%3E%3CH1%20id%3D%22toc-hId-558013521%22%20id%3D%22toc-hId-558013545%22%20id%3D%22toc-hId-558013545%22%20id%3D%22toc-hId-558013545%22%3EFit%20to%20one%20page%3C%2FH1%3E%3CDIV%3E%3CDIV%20class%3D%22appliesTo%20collapsed%22%3E%3CSPAN%20class%3D%22appliesToItem%22%3EExcel%20for%20Microsoft%20365%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22appliesToItem%22%3EExcel%20for%20the%20web%3C%2FSPAN%3E%20Excel%20%3CSPAN%20class%3D%22appliesToItem%22%3E2019%3C%2FSPAN%3E%20Excel%20%3CSPAN%20class%3D%22appliesToItem%22%3E2016%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22appliesToItem%22%3EExcel%202013%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22appliesTo%20collapsed%22%3E%3CSPAN%20class%3D%22appliesToItem%22%3E%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Foffice%2Ffit-to-one-page-f3015be3-e007-4762-90a7-19ebc8052511%3Fui%3Den-us%26amp%3Brs%3Den-us%26amp%3Bad%3Dus%23ID0EAACAAA%3DWeb%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Foffice%2Ffit-to-one-page-f3015be3-e007-4762-90a7-19ebc8052511%3Fui%3Den-us%26amp%3Brs%3Den-us%26amp%3Bad%3Dus%23ID0EAACAAA%3DWeb%3C%2FA%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22appliesTo%20collapsed%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22appliesTo%20collapsed%22%3E%3CP%3EThank%20you%20for%20your%20understanding%20and%20patience%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENikolino%3C%2FP%3E%3CP%3EI%20know%20I%20don't%20know%20anything%20(Socrates)%3C%2FP%3E%3C%2FDIV%3E%3CDIV%20class%3D%22appliesTo%20collapsed%22%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1767699%22%20slang%3D%22en-US%22%3EBetreff%3A%20VBA%20for%20Excel%20(365)%2C%20how%20to%20print%20to%20PDF%2C%20while%20scaling%20to%20fit%20all%20columns%20to%20a%20single%20page%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1767699%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F722750%22%20target%3D%22_blank%22%3E%40Nikolino%3C%2FA%3E%26nbsp%3BThanks%20for%20the%20reply.%26nbsp%3B%20I%20had%20a%20look%20at%20that%20link.%26nbsp%3B%20Unless%20I'm%20missing%20something%20though%2C%20it%20describes%20how%20to%20print%20using%20the%20GUI%20provided%20by%20the%20Excel%20application.%26nbsp%3B%20I'm%20asking%20how%20to%20print%20using%20VBA%20for%20Excel.%26nbsp%3B%20Did%20I%20miss%20that%20information%20somewhere%20in%20the%20link%20you%20provided%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

Hello. Using VBA for Excel (Office365), how can I print an Excel worksheet to PDF, while scaling to fit all columns to a single page wide? In my VBA script, I have already set: `FitToPagesWide = 1`. Here is more information.

 

For the past few years I've used Office 2013, and with it, a particular VBA for Excel script which would print a worksheet to PDF, while scaling to fit all columns to a single page wide. I recently updated to Office365 and the same VBA script is now printing to PDF, but not scaling to fit all columns to a single page wide. Any ideas why that is occurring and how to resolve it?


See this Pastebin for my VBA function.

 

Thanks in advance.

 

5 Replies
Highlighted

@cagross 

 

As far as I had to learn here...

(This information without guarantee, I would be happy to be instructed if it could work.
MS changes, develops and refines its products so well and quickly that you can hardly keep up with them. They are that good! :).

 

Click the Link for more info about this issue, Please:

This feature is not available in Excel for the web.

If you have the Excel desktop application, you can use the Open in Excel button to open the workbook and scale the worksheet to fit data on one page.

Fit to one page

Highlighted

@Nikolino Thanks for the reply.  I had a look at that link.  Unless I'm missing something though, it describes how to print using the GUI provided by the Excel application.  I'm asking how to print using VBA for Excel.  Did I miss that information somewhere in the link you provided?

Highlighted

@cagross 

 

All versions of Office 365 will allow execution and creation of Macros, it is only the free online version that will not.

Mean with it, only MicrosoftOffice 365 (browser version) does not support VBA macros.

Does Office 365 Online version supports VBA(visual basic for applications)?

https://social.technet.microsoft.com/Forums/office/en-US/7c46823c-2581-47a6-baac-66fb99ac3ea8/does-o...

Work with VBA macros in Excel for the web

Highlighted

@Nikolino I appreciate the reply, but those links aren't giving me any helpful information for my question.  I'm asking for specific help on why my VBA code isn't doing what I expect.

Highlighted

@cagross 

 

In order not to be misunderstood, the goal of some Excel users in the community is to provide help with projects by Excel users, or rather to provide food for thought.
As part of this excellent forum, my aim is to give help to get help where I can and need it.
That's why I try (like some others here) to help voluntarily as far as I can.

 

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        VerzeichnisName & "\" & Name, Quality:= _
        xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
        OpenAfterPublish:=True
With ActiveSheet.PageSetup
        .Zoom = False
        .Orientation = xlLandscape
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    End With
'Check your code to see if you have used zoom correctly.
'Is just a suggestion doesn't have to be right ... 
'because I know that I don't know anything.

 

 The only thing I can do for you is this VBA code.
But since I don't have a 365 Office desktop version (like you, as far as I could see your written version) I can't help you any further.
I think that one of Microsoft will take care of your question.
I'm sure they will give you a specific or official answer.
In the meantime, please be patient, we have weekend

 

Sorry that I took your time and couldn't give you a quick solution.

 

Wish you a nice day/night.

 

Nikolino

I know I don't know anything (Socrates)