方法导出对象'_Chart'失败运行时错误-2147286987 80030035

时间:2017-06-15 15:18:33

标签: excel vba excel-vba sharepoint

我已经设置了一个分配给按钮的宏,可以将每日报告推送到SharePoint网站。我可以运行该过程,因此另一个用户可以在不同位置的另一台计算机上运行。在同一位置的不同计算机上的另外两个用户不能并且得到'运行时错误-2147286987(80030035)方法导出对象'_Chart'失败。我完全失去了。如果这些相同的用户进入SharePoint并手动将相同的bmp保存到同一位置,则他们没有问题。所有参考文献也是一样的。我认为这是一个权限问题,但似乎并非如此。任何帮助表示赞赏。

这条线路失败了:

.Chart.Export "\\sharepoint-dns.com\sites\oursharepoint\SiteAssets\SitePages\Dashboard\" & sFile & ".bmp", "BMP"

完整的VBA如下所示。 PublishSharePoint调用SaveImage

Sub PublishSharePoint()

'User cell selection when running macro
Dim iRowRef As Integer
Dim iColRef As Integer
Dim iLastRow As Integer

SheetRef = ActiveSheet.Name
iRowRef = ActiveCell.Row
iColRef = ActiveCell.Column

'Unprotect Sheet
'Worksheets("Dashboard_3").Unprotect

Call SaveImage("Dashboard_3", "B5:O76", "Dashboard")

'Protect Sheet
'Worksheets("Dashboard_3").Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

'Return to starting cell
Worksheets(SheetRef).Activate
Cells(iRowRef, iColRef).Select

End Sub

...

Sub SaveImage(sSheet As String, sRange As String, sFile As String)

Worksheets(sSheet).Activate

Set Plage = ThisWorkbook.Worksheets(sSheet).Range(sRange)

Plage.CopyPicture

With ThisWorkbook.Worksheets(sSheet).ChartObjects.Add(Plage.Left, Plage.Top, Plage.Width, Plage.Height)
.Activate
.Chart.Paste
.Chart.ChartArea.Border.LineStyle = xlNone
'.Chart.Export "C:\...\" & nameFile & ".png", "PNG"
'.Chart.Export "C:\...\" & nameFile & ".jpg", "JPG"
.Chart.Export "\\sharepoint-dns.com\sites\oursharepoint\SiteAssets\SitePages\Dashboard\" & sFile & ".bmp", "BMP"
End With

Worksheets(sSheet).ChartObjects(Worksheets(sSheet).ChartObjects.Count).Delete

Set Plage = Nothing

End Sub

1 个答案:

答案 0 :(得分:0)

我不太了解详细解释根本原因,但这似乎与某些情况下需要网络凭据的webdav路径有关。作为一种解决方法,我将SharePoint路径映射为网络驱动器,这适用于所有用户。

Dim oNetwork As Object
Set oNetwork = CreateObject("WScript.Network")
oNetwork.MapNetworkDrive "Z:", "http://sharepoint-dns.com/sites/oursharepoint/SiteAssets/SitePages/Dashboard", False

请记得断开驱动器...

oNetwork.RemoveNetworkDrive "Z:"