Home

Possible bug in Excel for Mac 2016/2019/365

%3CLINGO-SUB%20id%3D%22lingo-sub-709413%22%20slang%3D%22en-US%22%3EPossible%20bug%20in%20Excel%20for%20Mac%202016%2F2019%2F365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-709413%22%20slang%3D%22en-US%22%3E%3CDIV%20class%3D%22post-text%22%3E%3CP%3EI'm%20making%20an%20Excel%20workbook%20for%20both%20Windows%20%26amp%3B%20Mac.%20I%20have%20a%20button%20in%20my%20workbook%20that%20allows%20the%20user%20to%20PRINT%20worksheets%20of%20their%20choice%2C%20and%20another%20that%20allows%20them%20to%20make%20a%20PDF%20of%20worksheets%20of%20their%20choice.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBoth%20buttons%20work%20perfectly%20on%20Windows.%20On%20Mac%202016%2F2019%2F365%2C%20the%20PDF%20button%20works%20fine.%20It%E2%80%99s%20the%20PRINT%20button%20that%20sometimes%20causes%20a%20problem.%20It%20doesn't%20work%20properly%20when%20the%20user%20has%20pressed%20the%20PDF%20button%20%3CEM%3Ebefore%3C%2FEM%3E%20pressing%20the%20PRINT%20button.%20In%20that%20case%2C%20the%20.PrintOut%20line%20of%20code%20either%20gives%20an%20error%2C%20or%20saves%20a%20PDF%20file%20instead%20of%20printing.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20I%20close%20the%20workbook%20and%20reopen%20it%2C%20it%20will%20print%20just%20fine%20%3CEM%3Euntil%3C%2FEM%3E%20I%20create%20a%20PDF%2C%20and%20then%20the%20problem%20happens%20again.%20I%20feel%20like%20this%20must%20be%20a%20bug%20in%20Excel%20for%20Mac%2C%20but%20am%20not%20100%25%20sure.%20I%20can%20only%20test%20it%20on%20my%20one%20Mac%20computer%2C%20so%20I%20know%20it's%20possible%20it%20might%20have%20something%20to%20do%20with%20my%20computer.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20is%20some%20simple%20code%20to%20test%20this.%20I%20appreciate%20anyone%20who%20would%20try%20this%20on%20their%20Mac%20and%20let%20me%20know%20the%20results.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESub%20PrintButton()%3C%2FP%3E%3CP%3E'this%20should%20send%20Sheet1%20to%20the%20default%20printer%3CBR%20%2F%3EThisWorkbook.Sheets(%22Sheet1%22).PrintOut%20Preview%3A%3DFalse%2C%20IgnorePrintAreas%3A%3DFalse%3C%2FP%3E%3CP%3EEnd%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESub%20PDFButton()%3C%2FP%3E%3CP%3E'this%20should%20create%20a%20PDF%20file%20of%20Sheet1%20on%20the%20Desktop%20of%20the%20Mac%3C%2FP%3E%3CP%3EDim%20UserName%20As%20String%3CBR%20%2F%3EDim%20FileNameAndPath%20As%20String%3C%2FP%3E%3CP%3EThisWorkbook.Sheets(%22Sheet1%22).Activate%3C%2FP%3E%3CP%3EUserName%20%3D%20MacScript(%22do%20shell%20script%20%22%22echo%20%24USER%22%22%22)%3C%2FP%3E%3CP%3EFileNameAndPath%20%3D%20%22%2FUsers%2F%22%20%26amp%3B%20UserName%20%26amp%3B%20%22%2FDesktop%2FTestPDF.pdf%22%3C%2FP%3E%3CP%3EActiveSheet.ExportAsFixedFormat%20Type%3A%3DxlTypePDF%2C%20Filename%3A%3D%20_%3CBR%20%2F%3EFileNameAndPath%2C%20Quality%3A%3DxlQualityStandard%2C%20_%3CBR%20%2F%3EIncludeDocProperties%3A%3DTrue%2C%20IgnorePrintAreas%3A%3DFalse%3C%2FP%3E%3CP%3EEnd%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20way%20to%20test%20it%20is%3A%3C%2FP%3E%3COL%3E%3CLI%3E%3CP%3ERun%20the%20PrintButton%20sub.%20It%20should%20send%20%22Sheet1%22%20to%20your%20printer.%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3ERun%20the%20PDFButton%20sub.%20It%20should%20create%20a%20PDF%20of%20%22Sheet1%22%20on%20your%20desktop.%3C%2FP%3E%3C%2FLI%3E%3CLI%3E%3CP%3ERun%20the%20PrintButton%20sub%20again.%20This%20is%20where%20the%20problem%20is%20happening%20for%20me.%20I%20am%20curious%20if%20it%20works%20properly%20for%20you%2C%20or%20if%20you%20receive%20an%20error%3F%20I%20received%20Run-time%201004%20error.%20(I%20have%20seen%20in%20some%20circumstances%20that%20instead%20of%20it%20printing%20the%20sheet%20here%20or%20throwing%20the%20error%2C%20it%20makes%20a%20PDF%20when%20it%20gets%20to%20the%20.PrintOut%20line.)%3C%2FP%3E%3C%2FLI%3E%3C%2FOL%3E%3CP%3EI%20created%20a%20workbook%20that%20has%20this%20code%20in%20it%20already%2C%20if%20you%20would%20rather%20download%20it%20and%20try%20it%20that%20way.%26nbsp%3B%20You%20can%20download%20it%20here%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fwww.dropbox.com%2Fs%2Flsrsui1st2bomxq%2FTestWorkbook-PrintAndPDF_Mac.xlsm%3Fdl%3D0%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.dropbox.com%2Fs%2Flsrsui1st2bomxq%2FTestWorkbook-PrintAndPDF_Mac.xlsm%3Fdl%3D0%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20to%20anyone%20who%20tries%20it%20for%20me.%26nbsp%3B%20I'm%20very%20curious%20to%20see%20if%20this%20is%20an%20actual%20bug%20in%20Excel%20for%20Mac.%26nbsp%3B%20If%20it%20is%2C%20I'm%20curious%20if%20anyone%20knows%20of%20a%20work-around%3F%3C%2FP%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E
mcomp72
Visitor

I'm making an Excel workbook for both Windows & Mac. I have a button in my workbook that allows the user to PRINT worksheets of their choice, and another that allows them to make a PDF of worksheets of their choice.

 

Both buttons work perfectly on Windows. On Mac 2016/2019/365, the PDF button works fine. It’s the PRINT button that sometimes causes a problem. It doesn't work properly when the user has pressed the PDF button before pressing the PRINT button. In that case, the .PrintOut line of code either gives an error, or saves a PDF file instead of printing.

 

If I close the workbook and reopen it, it will print just fine until I create a PDF, and then the problem happens again. I feel like this must be a bug in Excel for Mac, but am not 100% sure. I can only test it on my one Mac computer, so I know it's possible it might have something to do with my computer.

 

Here is some simple code to test this. I appreciate anyone who would try this on their Mac and let me know the results.

 

Sub PrintButton()

'this should send Sheet1 to the default printer
ThisWorkbook.Sheets("Sheet1").PrintOut Preview:=False, IgnorePrintAreas:=False

End Sub

 

Sub PDFButton()

'this should create a PDF file of Sheet1 on the Desktop of the Mac

Dim UserName As String
Dim FileNameAndPath As String

ThisWorkbook.Sheets("Sheet1").Activate

UserName = MacScript("do shell script ""echo $USER""")

FileNameAndPath = "/Users/" & UserName & "/Desktop/TestPDF.pdf"

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
FileNameAndPath, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False

End Sub

 

The way to test it is:

  1. Run the PrintButton sub. It should send "Sheet1" to your printer.

  2. Run the PDFButton sub. It should create a PDF of "Sheet1" on your desktop.

  3. Run the PrintButton sub again. This is where the problem is happening for me. I am curious if it works properly for you, or if you receive an error? I received Run-time 1004 error. (I have seen in some circumstances that instead of it printing the sheet here or throwing the error, it makes a PDF when it gets to the .PrintOut line.)

I created a workbook that has this code in it already, if you would rather download it and try it that way.  You can download it here:

https://www.dropbox.com/s/lsrsui1st2bomxq/TestWorkbook-PrintAndPDF_Mac.xlsm?dl=0

 

Thanks to anyone who tries it for me.  I'm very curious to see if this is an actual bug in Excel for Mac.  If it is, I'm curious if anyone knows of a work-around?

Related Conversations
Extentions Synchronization
Deleted in Discussions on
3 Replies
Tabs and Dark Mode
cjc2112 in Discussions on
35 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
29 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
9 Replies