cashr23523
Programmer
- Nov 14, 2007
- 2
I am working on a project that consists of importing several CSV files into an Excel workbook, then for each worksheet creating custom charts based off the numerical data in the worksheet. Everything works fine until I encounter a CSV file with a name longer than 31 characters in which I use to name the appropriate worksheet in Excel. After I truncate the name to make it less that 31 characters, add a new worksheet with that truncated name, and then try to add a custom chart on that same page it never works properly. However, if the string name doesn’t need to be truncated it works properly and pastes the chart correctly on the sheet. I don’t remember ever having this problem before but it is the only logical reasoning I can find that is causing this error. The code I am using to create the chart is:
ActiveSheet.Range(ExcelSht.Cells(top, 1), ExcelSht.Cells(bot, varNewLastCol)).Select
Charts.Add
ActiveChart.ApplyCustomType ChartType:=xlUserDefined, TypeName:=tpName
ActiveChart.SetSourceData Source:=Sheets(name).Range(ExcelSht.Cells(top, 1), ExcelSht.Cells(bot, varNewLastCol)), PlotBy:=xlRows
ActiveChart.Location Where:=xlLocationAsObject, name:=name code fails here; name is the same as the worksheet name being passed to the procedure. Works for sheets whose name < 31 caharacters and doesn’t need to be truncated but not for those > 31 whose name has already been truncated and worksheet has been created before calling this line of code.
With ActiveChart
'.HasTitle = False
'.ChartTitle.Characters.Text = UCase(ActiveSheet.name) & " - CPE Per Feature Chart 1"
'.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = varChart1(0)
'.Axes(xlCategory, xlSecondary).HasTitle = False
.Axes(xlValue, xlSecondary).HasTitle = True
.Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = varChart1(1)
.Axes(xlValue, xlSecondary).MinimumScale = lmin
.Axes(xlValue, xlSecondary).MaximumScale = lmax
.Axes(xlValue, xlSecondary).TickLabels.NumberFormat = "$#,##0"
.Axes(xlValue, xlPrimary).MinimumScale = rmin
.Axes(xlValue, xlPrimary).MaximumScale = rmax
End With
What happens is the chart is created properly on a different worksheet as an object but never pastes onto the proper worksheet because the code fails at the point mentioned above. Anyone had any similar experiences with this or is there another solution? Any help is greatly appreciated.
ActiveSheet.Range(ExcelSht.Cells(top, 1), ExcelSht.Cells(bot, varNewLastCol)).Select
Charts.Add
ActiveChart.ApplyCustomType ChartType:=xlUserDefined, TypeName:=tpName
ActiveChart.SetSourceData Source:=Sheets(name).Range(ExcelSht.Cells(top, 1), ExcelSht.Cells(bot, varNewLastCol)), PlotBy:=xlRows
ActiveChart.Location Where:=xlLocationAsObject, name:=name code fails here; name is the same as the worksheet name being passed to the procedure. Works for sheets whose name < 31 caharacters and doesn’t need to be truncated but not for those > 31 whose name has already been truncated and worksheet has been created before calling this line of code.
With ActiveChart
'.HasTitle = False
'.ChartTitle.Characters.Text = UCase(ActiveSheet.name) & " - CPE Per Feature Chart 1"
'.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = varChart1(0)
'.Axes(xlCategory, xlSecondary).HasTitle = False
.Axes(xlValue, xlSecondary).HasTitle = True
.Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = varChart1(1)
.Axes(xlValue, xlSecondary).MinimumScale = lmin
.Axes(xlValue, xlSecondary).MaximumScale = lmax
.Axes(xlValue, xlSecondary).TickLabels.NumberFormat = "$#,##0"
.Axes(xlValue, xlPrimary).MinimumScale = rmin
.Axes(xlValue, xlPrimary).MaximumScale = rmax
End With
What happens is the chart is created properly on a different worksheet as an object but never pastes onto the proper worksheet because the code fails at the point mentioned above. Anyone had any similar experiences with this or is there another solution? Any help is greatly appreciated.