perola.rike
Board Regular
- Joined
- Nov 10, 2011
- Messages
- 151
I have 300 rows of data (psychological tests) that are converted to text and exported from Excel to a formatted report in Word (the code for this is approx 500 lines so only an extract of this code is pasted in this thread, the "export chart" part).
Part of this Word-report, the data in use are graphically presented in a chart.
Unfortunately, the chart are pasted at the bottom of the Word document, I want it to be pasted in a specific place inbetween some specific text lines.
I've read some about Word bookmarking etc, but I really can't figure it out and make it fit my code.
Any tips on how to paste the chart in a specific place in the Word report?
The whole code is saved as a txt document here: https://www.dropbox.com/s/du3dp9vs1qoisyy/code report.txt?dl=0
Best regards,
Per-Ola
'Copy/paste profilchart
'Dim word As Object
Dim doc As Object
Dim chrt As ChartObject
' Dim i As Integer
On Error Resume Next
'(For i = 1 To 1)
Sheets("profilark").Activate
For Each chrt In ActiveSheet.ChartObjects
i = i + 1
Next
ActiveSheet.ChartObjects.Item(i).Activate
ActiveChart.CopyPicture Appearance:=xlScreen, Format:=xlPicture
With WordApp.Selection
'Paster Chart
.Range.Paste
Application.CutCopyMode = False
End With
'Save the Word file And Close it
With WordApp
.ActiveDocument.SaveAs Filename:=SaveAsName
.ActiveWindow.Close
'Kill the Object
.Quit
End With
Set word = Nothing
'Reset status bar
Application.StatusBar = ""
MsgBox "Autoreport " & savename & ".doc was saved in " & ThisWorkbook.Path
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic
Part of this Word-report, the data in use are graphically presented in a chart.
Unfortunately, the chart are pasted at the bottom of the Word document, I want it to be pasted in a specific place inbetween some specific text lines.
I've read some about Word bookmarking etc, but I really can't figure it out and make it fit my code.
Any tips on how to paste the chart in a specific place in the Word report?
The whole code is saved as a txt document here: https://www.dropbox.com/s/du3dp9vs1qoisyy/code report.txt?dl=0
Best regards,
Per-Ola
'Copy/paste profilchart
'Dim word As Object
Dim doc As Object
Dim chrt As ChartObject
' Dim i As Integer
On Error Resume Next
'(For i = 1 To 1)
Sheets("profilark").Activate
For Each chrt In ActiveSheet.ChartObjects
i = i + 1
Next
ActiveSheet.ChartObjects.Item(i).Activate
ActiveChart.CopyPicture Appearance:=xlScreen, Format:=xlPicture
With WordApp.Selection
'Paster Chart
.Range.Paste
Application.CutCopyMode = False
End With
'Save the Word file And Close it
With WordApp
.ActiveDocument.SaveAs Filename:=SaveAsName
.ActiveWindow.Close
'Kill the Object
.Quit
End With
Set word = Nothing
'Reset status bar
Application.StatusBar = ""
MsgBox "Autoreport " & savename & ".doc was saved in " & ThisWorkbook.Path
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic