ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro run time error (https://www.excelbanter.com/excel-programming/377328-re-macro-run-time-error.html)

Jim Jackson

Macro run time error
 
Replace Windows("Savings for Single Country Reporting.xls").Activate with
ThisWorkbook.Activate and it will work regardless of the actual name.
--
Best wishes,

Jim


"juliejg1" wrote:

I have created a macro in a workbook that is being used and run by other
people. Each person is naming their workbook something unique.
Unfortunately, that seems to cause problems for the macro. They receive a
run-time error 'subscript out of range'. The code were it is breaking is as
follows:

ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(2).Values = "=Formulas!R11C2"
ActiveWindow.Visible = False
Windows("Savings for Single Country Reporting.xls").Activate
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(2).Values = "=Formulas!R17C2"
ActiveWindow.Visible = False
Windows("Savings for Single Country Reporting.xls").Activate
ActiveCell.Select

This is where the code breaks:

Windows("Savings for Single Country Reporting.xls").Activate


The workbook was renamed by it's new owner to 'LA Draft'. Several other
workbooks were also renamed to different names.




juliejg1

Macro run time error
 
Worked perfectly!! Thanks Jim

"Jim Jackson" wrote:

Replace Windows("Savings for Single Country Reporting.xls").Activate with
ThisWorkbook.Activate and it will work regardless of the actual name.
--
Best wishes,

Jim


"juliejg1" wrote:

I have created a macro in a workbook that is being used and run by other
people. Each person is naming their workbook something unique.
Unfortunately, that seems to cause problems for the macro. They receive a
run-time error 'subscript out of range'. The code were it is breaking is as
follows:

ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(2).Values = "=Formulas!R11C2"
ActiveWindow.Visible = False
Windows("Savings for Single Country Reporting.xls").Activate
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(2).Values = "=Formulas!R17C2"
ActiveWindow.Visible = False
Windows("Savings for Single Country Reporting.xls").Activate
ActiveCell.Select

This is where the code breaks:

Windows("Savings for Single Country Reporting.xls").Activate


The workbook was renamed by it's new owner to 'LA Draft'. Several other
workbooks were also renamed to different names.




Jim Jackson

Macro run time error
 
I'm always glad to help. Having received my share of help from this group, I
feel good being able to contribute.
--
Best wishes,

Jim


"juliejg1" wrote:

Worked perfectly!! Thanks Jim

"Jim Jackson" wrote:

Replace Windows("Savings for Single Country Reporting.xls").Activate with
ThisWorkbook.Activate and it will work regardless of the actual name.
--
Best wishes,

Jim


"juliejg1" wrote:

I have created a macro in a workbook that is being used and run by other
people. Each person is naming their workbook something unique.
Unfortunately, that seems to cause problems for the macro. They receive a
run-time error 'subscript out of range'. The code were it is breaking is as
follows:

ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(2).Values = "=Formulas!R11C2"
ActiveWindow.Visible = False
Windows("Savings for Single Country Reporting.xls").Activate
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(2).Values = "=Formulas!R17C2"
ActiveWindow.Visible = False
Windows("Savings for Single Country Reporting.xls").Activate
ActiveCell.Select

This is where the code breaks:

Windows("Savings for Single Country Reporting.xls").Activate


The workbook was renamed by it's new owner to 'LA Draft'. Several other
workbooks were also renamed to different names.





All times are GMT +1. The time now is 02:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com