Why does my macro create new sheets with a different default colour

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,212
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
I have a macro that simple copys tabs into there own sheet, (I'll leave a copy below)
But when it create these new tabs, the colour is different to the colour I have and it turns out it because its defaulting to Office colours instead of Office 2013 -2022
I then have to mgo back in and change this and save it. (As the actor said to the actress "This has never happened to me before!"

so two question
One any idea why?

two and more importantly
can I add something to this macro that macks the new workbook set as Office 2013 -2022?

Thanks
Tony

VBA Code:
Sub CopySheetsWithTabColor()
    Dim ws As Worksheet
    Dim newWorkbook As Workbook
    Dim tabName As String
    Dim savePath As String
    Dim currentWorkbookPath As String
   

    currentWorkbookPath = ThisWorkbook.Path & "\"

    For Each ws In ThisWorkbook.Worksheets
        If ws.Tab.Color = RGB(68, 114, 196) Then
            tabName = ws.Name
                ws.Copy

            ActiveWorkbook.SaveAs Filename:= _
                currentWorkbookPath & "Hershey-" & tabName & " Supplier Summary EPI 2024.xlsx"

            ActiveWorkbook.Close SaveChanges:=False
        End If
    Next ws

    MsgBox "Sheets with the specified tab color have been copied and saved.", vbInformation
End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try inserting this line of code:
VBA Code:
ActiveSheet.Tab.Color = RGB(68, 114, 196)
below this line:
VBA Code:
ws.Copy
 
Upvote 0

Forum statistics

Threads
1,225,229
Messages
6,183,728
Members
453,185
Latest member
radiantclassy

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