Macro that refreshes the workbook, copies the sheet to a network workbook and changes the name in the copied to workbook to todays date

agentkramr

Board Regular
Joined
Dec 27, 2021
Messages
98
Platform
  1. Windows
i have a workbook that populates data from an Oracle database.
With my VBA i am trying to refresh the workbook , copy that page to a network workbook and then name the tab in the network workbook to todays date
i am using AI1 to hold my value of todays date using a custom format of (mmm Dd)

VBA Code:
Sub CB_Copy()
'Refresh Workbook
Workbooks("My Workbook").RefreshAll
'Open a workbook

  'Open method requires full file path to be referenced.
  Workbooks.Open \\server\Shares\Folder\Sales\_Nightly Reports\2022 Nightly Reports\2022 2 Week Counts\2022 2 Week Count1.xlsx
 
  Workbooks("My Workbook.xlsm").Activate
 
  Sheets("2018 1 Hour Counts").Copy After:=Workbooks("2022 2 Week Count1.xlsx").Sheets(Workbooks("2022 2 Week Count1.xlsx").Sheets.Count)
    ActiveSheet.Range("A1:AC84").Copy
    ActiveSheet.Range("A1:AC84").PasteSpecial xlPasteValues
    'ActiveSheet.Shapes("Rectangle: Rounded Corners 1").Delete
    'ActiveSheet.Shapes("Rectangle: Rounded Corners 2").Delete
    Dim Val As String
    Val = Sheets("2018 1 Hour Counts").Range("AI1").Value
        ActiveSheet.Name = Val
    'Columns("AF:AI").Delete

    ActiveWorkbook.Save
    ActiveWorkbook.Close
End Sub

i get an error
"You typed an invalid name for a sheet or chart. Make sure that:
  • The name that you type does not exceed 31 charaters
  • The name does not contain any of the following characters: \ / ? * [ or ]
  • You dod not leave the name blank
if it hit debug it goes to the line ActiveSheet.Namer = Val

any help would be greatly appreciated
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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