macros not working right in Excel 2016 but work well in 2010

anasttin1

New Member
Joined
Jul 20, 2017
Messages
11
Hi,

I've designed several macros that seem to work fine in 2010, but gives errors and don't work properly in Excel 2016.

One macro is simply meant to print a screen, but the formats are all lost in 2016 for example.

The other macro filters data perfectly in 2010, but in 2016, it crashes without even giving me a "debug" button.

Can anyone offer any advice?

Many thanks in advance.

:)
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Do you think it might help if you posted the problem macros ??
 
Upvote 0
Do you think it might help if you posted the problem macros ??


Thanks Michael.

As an example, the print macro below returns:

"Run time error '1004'
Method "Printout' of object 'Sheets' failed

when run the first time in Excel 2016 the first time. Then if you run it again, it works. (No debug button)

It works every time in Excel 2010.

Thanks in advance.

===============================

Sub Bevel21_Click()
'
' Bevel21_Click Macro
'
Dim oneSheet As Worksheet
For Each oneSheet In ThisWorkbook.Worksheets
With oneSheet
.Unprotect "password"
.EnableOutlining = True
.EnableSelection = xlNoRestrictions
End With
Next oneSheet


'set groups
Columns("BL:CB").Select
Selection.Columns.Group
Columns("AC:AC").Select
Selection.Columns.Group
Columns("AF:AM").Select
Selection.Columns.Group
Columns("AO:AP").Select
Selection.Columns.Group
Columns("AY:BA").Select
Selection.Columns.Group
Columns("BD:BE").Select
Selection.Columns.Group

ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=1

Columns("AE:AE").ColumnWidth = 8
Columns("AN:AN").ColumnWidth = 8
Columns("AQ:AX").ColumnWidth = 8
Columns("BB:BC").ColumnWidth = 12
Columns("BF:BK").ColumnWidth = 8

mylow = Range("AA10000").End(xlUp).Row
ActiveSheet.PageSetup.PrintArea = "$AA$32:$BK$" & mylow
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=2

'Ctrl-Home
Application.Goto Range("A1"), True
ActiveWindow.VisibleRange(1, 1).Select

'Clear print area
ActiveSheet.PageSetup.PrintArea = ""

'Remove subgroups
Columns("Z:CH").Select
Selection.Columns.Ungroup

For Each oneSheet In ThisWorkbook.Worksheets
With oneSheet
.Protect Password:="password", UserInterFaceOnly:=True, AllowFiltering:=True, AllowFormattingColumns:=True
.EnableOutlining = True
.EnableSelection = xlNoRestrictions
End With
Next oneSheet
Sheets("WIF Consol").Unprotect Password:="password"
Sheets("Data").Unprotect Password:="password"


MsgBox "Sent to printer"


End Sub
 
Upvote 0
If you step through the code manually, where does it error.
If here
Code:
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False

Try changing selectedsheets to either Activesheet OR the actual sheet name....Sheets("The sheet name")

It worked fine for first time in 2007 and 2013
 
Upvote 0
If you step through the code manually, where does it error.
If here
Code:
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False

Try changing selectedsheets to either Activesheet OR the actual sheet name....Sheets("The sheet name")

It worked fine for first time in 2007 and 2013

I'll definitely give it a go Michael, but I'm much more interested to understand why the same code would error in 2016, but not 2010.

The problem is that I'm constantly developing macros in 2010 and some users are on 2016 so its not just 2 macros I'm really talking about.
 
Upvote 0
Can't help you there, I can't see why it wouldn't work in 2016
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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