Hi there,
I am trying to copy and paste a chart from Excel into Word using from Word. I have made Microsoft Excel 14.0 object library available for reference.
I am able to open the excel workbook, navigate to the sheet and chart, and then copy the chart. However, I am having trouble navigating back to the word doc, pasting in, and then closing the excel workbook.
My code so far is:
Option Explicit
Sub PC()
Dim Month As String
Dim objXLApplication As Excel.Application
Dim objXLWorkbook As Excel.Workbook
' Get month that analysis is required for
Month = InputBox("Enter month required")
'Open workbook
Set objXLApplication = CreateObject("Excel.Application")
Set objXLWorkbook = objXLApplication.Workbooks.Open("C:\Users\" + Month + " 2011.xlsm")
objXLApplication.Visible = True
' Go to the worksheet and copy graph
Sheets("Power Curve").Select
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveChart.ChartArea.Copy
'''Problems from here on
' Activate Word Doc and paste in
Documents("C:\Users\ " + Month + " 2011.docm").Activate
End Sub
Any help greatly appreciated!
I am trying to copy and paste a chart from Excel into Word using from Word. I have made Microsoft Excel 14.0 object library available for reference.
I am able to open the excel workbook, navigate to the sheet and chart, and then copy the chart. However, I am having trouble navigating back to the word doc, pasting in, and then closing the excel workbook.
My code so far is:
Option Explicit
Sub PC()
Dim Month As String
Dim objXLApplication As Excel.Application
Dim objXLWorkbook As Excel.Workbook
' Get month that analysis is required for
Month = InputBox("Enter month required")
'Open workbook
Set objXLApplication = CreateObject("Excel.Application")
Set objXLWorkbook = objXLApplication.Workbooks.Open("C:\Users\" + Month + " 2011.xlsm")
objXLApplication.Visible = True
' Go to the worksheet and copy graph
Sheets("Power Curve").Select
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveChart.ChartArea.Copy
'''Problems from here on
' Activate Word Doc and paste in
Documents("C:\Users\ " + Month + " 2011.docm").Activate
End Sub
Any help greatly appreciated!