Word VBA Code

chandrashekar

Well-known Member
Joined
Jul 15, 2005
Messages
529
Office Version
  1. 365
Platform
  1. Windows
Hi,

am trying to paste excel graph to word using vbacode(using word) but I need to paste it in particular positions. May I know how to do it?

Please find below code which am using now.
Code:
Sub excel2word()

    
    Dim oExcel As Excel.Application
    Dim oWB As Workbook
    Set oExcel = New Excel.Application
    Set oWB = oExcel.Workbooks.Open("C:\Users\Chandra.char\Desktop\Test\VR.xls")
    oExcel.Visible = True
    oWB.Sheets("ViolationCount_Week").Select
    

    Set Chart = oWB.Sheets("ViolationCount_Week").ChartObjects("Chart 6")
    Chart.Copy
    'Chart.ChartArea.Copy
    With ActiveDocument.Sections(1).Range
       .PasteSpecial Link:=False, DataType:=wdPasteBitmap, _
            Placement:=wdInLine, DisplayAsIcon:=False
    End With
    
    Set oExcel = Nothing
    Set oWB = Nothing
    Set Chart = Nothing
End Sub
 
Last edited by a moderator:
I am getting error in The requested member of the collection does not exist in line
ActiveDocument.SelectContentControlsByTitle("Chart")(1).Range.Paste
As I said in post #8:
Where the content control's title is 'Chart'. Note that the content control must exist in the document before running the macro.
Did you insert a picture content control into the document and title it 'Chart' before running the macro? The error message suggests not.
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
The code works just fine in my testing, so I can only conclude you have miss-named the content control or that it doesn't exist in the active document.
 
Upvote 0
No, you can't do that. If you want someone to look at them, upload them to a OneDrive or another file hosting site and post a link here.
 
Upvote 0

Forum statistics

Threads
1,225,759
Messages
6,186,863
Members
453,380
Latest member
ShaeJ73

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top