Passing File Name when creating ChartSeriesCollection

MRTX7005

New Member
Joined
Aug 6, 2017
Messages
8
When I create the Chart on a worksheet, the Excel file name is being used in creating the Chart SeriesCollection. I am struggling with figuring out how to pass the Excel file name as a variable when creating the chart. I want the user to be able to call the Excel file whatever they want vs what I programmed the first time.

The Excel file is currently called "Electric_DCApp". This is what I want to make a variable instead.

Code:
Charts.Add
    ActiveChart.ChartType = xlLine
    ActiveChart.SetSourceData Source:=Sheets("Dashboard").Range("A1")
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.SeriesCollection(1).XValues = "=Electric_DCApp.xlsm!ChtTime"
    ActiveChart.SeriesCollection(1).Values = "=Electric_DCApp.xlsm!ChtDSRPM"
    ActiveChart.SeriesCollection(1).Name = "=Data!R1C8"
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Dashboard"

I have tried using something like:
Code:
Dim fName As String
fName = ThisWorkbook.FullName
Then replaced the "=Electric_DCApp.xsm!ChtTime" with "=fName!ChtTime" as an example but that does not work.

Any help would be appreciated.
Mike
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try this


Code:
ActiveChart.SeriesCollection(1).XValues = "='" & fName & "'!ChtTime"
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
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