0

Currently I'm using the following code to export my diagram as JPG and save it in the worksheet directory.

Sub exportDiagram_Click()
    Dim myChart As Chart
    Dim filePath As String

    Set objChrt = Sheets("Diagrams").ChartObjects("dashboardExport")
    Set myChart = objChrt.Chart

    filePath = ThisWorkbook.Path & "\export.jpg"

    myChart.Export Filename:=filePath, Filtername:="JPG"
End Sub

Since I uploaded this Excel file to Sharepoint my code doesn't work anymore.

How do I create this JPG file and upload it to Sharepoint from Excel?

Thanks

0

After some trying I got the following solution which is fine for me:

Sub exportDiagram_Click()
    Dim myChart As Chart
    Dim SharepointAddress As String
    Dim objNet As Object
    Dim FS As Object

    ' output path '
    SharepointAddress = "\\sharepoint\documents\example.jpg"

        Set objChrt = Sheets("mySheet").ChartObjects("diagramExport")
        Set myChart = objChrt.Chart
        Set objNet = CreateObject("WScript.Network")
        Set FS = CreateObject("Scripting.FileSystemObject")

    ' remove old file from target '
    If FS.FileExists(SharepointAddress) Then
        SetAttr SharepointAddress, vbNormal
        Kill SharepointAddress
    End If

    ' export as JPG '
    myChart.Export FileName:=SharepointAddress, Filtername:="JPG"

    Set objNet = Nothing
    Set FS = Nothing
End Sub

Now when I press the button in my Excel file it exports the diagramExport diagram right into my Sharepoint documents.

I hope this helps some others. Greets

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.