Permalink
Cannot retrieve contributors at this time
title | description | author | manager | localization_priority | search.appverid | audience | ms.topic | ms.author | ms.custom | appliesto | ms.date | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Run-time error-2147467259 (80004005) when you set a property of a chart |
Describes a problem in which you receive a run-time error message when you programmatically set a property of a chart in Excel. Provides a workaround for this problem. |
helenclu |
dcscontentpm |
Normal |
MET150 |
ITPro |
troubleshooting |
luche |
CSSTroubleshoot |
|
3/31/2022 |
Run-time error-2147467259 (80004005) when you set a property of a chart
Symptoms
Consider the following scenario:
- You have a macro that sets a property of a chart in Microsoft Excel. For example, the macro sets the MaximumScale, MinimumScale, Title, Axis, or Legendproperty of a chart.
- You protect the worksheet. When you do this, you click to select the Edit objects check box in the Protect Sheet dialog box.
- You run the macro.
In this scenario, you receive an error message that resembles one of the following.
Error message 1
Run-time error '-2147467259 (80004005)': Method 'MaximumScale' of object 'Axis' failed
Error message 2
Run-time error '-2147467259 (80004005)':
Automation error
Unspecified error
Cause
This problem occurs because the Excel object model for the chart is disabled on a protected worksheet.
Workaround
To work around this problem, unprotect the worksheet to enable the macro to run. You can manually unprotect the worksheet or by using the Unprotect method in the macro.
Status
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the «Applies to» section.
Ash —
In your code, try adding series data and category labels prior to assigning the axis scales.
I can successfully run this code on a chart so long as there is at least 1 series, and the category axis labels are in date format.
I have uploaded a workbook to Google Docs which has the chart already created. Delete the chart, but leave the series data in columns B&C, then run the macro AshOriginalWithAddSeries
. All I have done really is to add one series of data with date-formatted XValues
, and then your code works.
https://docs.google.com/file/d/0B1v0s8ldwHRYUWUtRWpqblgzM3M/edit?usp=sharing
Sub AshOriginalWithAddSeries()
Dim cht As Chart
Dim srs As Series
Dim dummyDate As Date
Set cht = ActiveSheet.ChartObjects.Add(Left:=202, Width:=340, Top:=28, Height:=182).Chart
dummyDate = DateSerial(2013, 2, 1)
' remove extra series
With cht
Do Until .SeriesCollection.Count = 0
.SeriesCollection(1).Delete
Loop
'Add at least one series:
Set srs = .SeriesCollection.NewSeries
With srs
.Name = "Series Title"
.Values = 0.5 '=Working!$C$3:$C$14" ' or you can pass an array of stored values
.XValues = Array(dummyDate) '"=Working!$B$3:$B$14" 'or you can pass an array of values, make sure they are valid DATES though
End With
.ChartType = xlLineMarkers
.HasTitle = True
.ChartTitle.Text = "Performance Trends"
.ChartTitle.Font.Size = 12
.ChartTitle.Font.Name = "Calibri"
.ChartTitle.Font.FontStyle = "Bold"
With .Axes(xlCategory)
.CategoryType = xlTimeScale
'.BaseUnit = xlMonths
.MajorUnit = 2
.TickLabels.NumberFormat = "mmm yy"
.TickLabels.Orientation = 45
'.MajorUnitScale = xlMonths ' run-time error occurs here
.MinorUnit = 1
'.MinorUnitScale = xlMonths
End With
End With
'Now assign some real values to srs
With srs
.Name = "Series Title"
.Values = "=Working!$C$3:$C$14" ' or you can pass an array of stored values
.XValues = "=Working!$B$3:$B$14" 'or you can pass an array of values, make sure they are valid DATES though
End With
End Sub
I think your code is failing because there is no series data, and consequently no category values. It is peculiar because some properties of the axis can be set even when the axis doesn’t exist. I have noticed similar behavior elsehwere in chart automation — sometimes it won’t let you access the properties unless there is series data.
- Remove From My Forums
-
Вопрос
-
While running a VBA Macro to paste Graphs into PPT; I am getting the following error.
================================================================
Microsoft Visual Basic
Run-time error’-2147467259(80004005):
Presentation (unknown member): The Path or filename for c:tempfilename.ppt is invalid. Please check that the path and file name are correct.================================================================
However; this macro was running earlier without any errors and suddenly showing this error. The same macro is still running without any errors in other computers. Please help me find a solution to this problem.
Thanks,
Arul
Ответы
-
Hi Arul,
According to the error message, the file you operate is invalid. I suggest you check the c:tempfilename.ppt
to see whether it exists or is corruped. If the file can be opened successfully, wolud you mind sharing the the code snippet with us to troubleshoot this issue?Best regards
Fei
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.-
Помечено в качестве ответа
7 февраля 2014 г. 9:29
-
Помечено в качестве ответа
Странное выполнение кода |
||||||||
Ответить |
||||||||
Ответить |
||||||||
Ответить |
||||||||
Ответить |
||||||||
Ответить |
||||||||
Ответить |
Всем добрый вечер!! в строке кода: появляется ошибка: помогите пожалуйста — как ее избежать? причем — если pdf уже существует (то есть, если сохранение идет поверх существующего), то вроде ошибка не выскакивает. подскажите пожалуйста команду создания пустого pdf файла-заглушки. (не сохранять или печатать в pdf, а именно просто создать. что-нибудь типа FSO.Makefile («C:111.pdf») |
|
Юрий М Модератор Сообщений: 60574 Контакты см. в профиле |
Для начала попробуйте в диспетчере задач посмотреть — есть ли там среди открытых документов Ваши. И закройте там же само приложение. |
процесса WINWORD.EXE нету даже если есть куча процессов WINWORD.EXE — перезапись(!) файла делается отлично, при условии, если файл pdf уже существует. таким образом, ошибка появляется только при создании нового файла. вот и хочу перед выполнением функции создавать макросом пустой файл-заглушку, чтобы он в любом случае перезаписывался и не было ошибок |
|
вставила перед выполнением функции: |
|
Hugo Пользователь Сообщений: 23250 |
Бывает, что в корень C запрещает писать система или антивирус. |
а вот еще нашла решение: http://tiny.cc/u28bdw по первичным тестам ошибка тоже не выскакивает вместо: заменить на: |
|
точнее так: |
|
_Лена_ Гость |
#8 26.04.2012 00:57:19 а нет ну буду значит через пустой файл-заглушку делать (msg 26.04.2012, 00:13) |