silentwolf
Active member
- Local time
- Today, 15:55
- Joined
- Jun 12, 2009
- Messages
- 644
Hi guys,
unfortunatelly I am getting an runtime Error 438, Object not supported.
When I try to copy a Chart from an Excel Worksheet.
here is the Code.
"Hole Anwendung"
and the code I am trying to use to insert a Diagram to a Word Document
In my workbook I have created a Diagramm1 for some data which is in the worksheet "Diagramm1"
I can not figure out how I can refer to the diagramm so I hope to get som advice from you!
The issue is on the line " wkbExcel.Diagramm1.ChartArea.Copy"
Many thanks
Albert
unfortunatelly I am getting an runtime Error 438, Object not supported.
When I try to copy a Chart from an Excel Worksheet.
here is the Code.
"Hole Anwendung"
Code:
Function HoleAnwendung(strName As String) As Object
On Error Resume Next
Set HoleAnwendung = GetObject(, strName)
If HoleAnwendung Is Nothing Then
Set HoleAnwendung = CreateObject(strName)
End If
End Function
and the code I am trying to use to insert a Diagram to a Word Document
Code:
Sub CreateBasicWordReportFromTemplate()
Set m_appWord = HoleAnwendung("Word.Application")
Dim SaveName As String
Dim FileExt As String
With m_appWord
' .Visible = True
' .Activate
.Documents.Add ("C:\Users\Albert\AppData\Roaming\Microsoft\Templates\Movie Report Template.dotx")
Set m_appExcel = HoleAnwendung("Excel.Application")
Dim wkbExcel As Excel.Workbook
Dim wksExcel As Excel.Worksheet
Set wkbExcel = m_appExcel.Workbooks.Open("C:\Users\Albert\Desktop\Movies.xlsx")
Set wksExcel = wkbExcel.Worksheets("Tabelle1")
wksExcel.Range("A2", wksExcel.Range("A2").End(xlDown).End(xlToRight)).Copy
' .Selection.GoTo wdGoToBookmark 'early binding
.Selection.GoTo what:=-1, Name:="TableLocation" 'late binding
.Selection.Paste
wkbExcel.Diagramm1.ChartArea.Copy
.Selection.GoTo what:=-1, Name:="ChartLocation" 'late binding
.Selection.Paste
If .Version <= 11 Then
FileExt = ".doc"
Else
FileExt = "docx"
End If
SaveName = Environ("UserProfile") & "\Desktop\Movie Report " & _
Format(Now, "yyyy-mm-dd-hh-mm-ss") & FileExt
If .Version <= 12 Then
.ActiveDocument.SaveAs SaveName
Else
.ActiveDocument.SaveAs2 SaveName
End If
.ActiveDocument.Close
.Quit
wkbExcel.Close
m_appExcel.Quit
End With
Set m_appWord = Nothing
Set m_appExcel = Nothing
End Sub
In my workbook I have created a Diagramm1 for some data which is in the worksheet "Diagramm1"
I can not figure out how I can refer to the diagramm so I hope to get som advice from you!
The issue is on the line " wkbExcel.Diagramm1.ChartArea.Copy"
Many thanks
Albert