+ Reply to Thread
Results 1 to 2 of 2

Getobject()

Hybrid View

  1. #1
    Registered User
    Join Date
    02-03-2012
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    1

    Getobject()

    Hi all,

    I am basically trying to copy data from an excel document to a word document both of which are already open.

    Since I know the name of the Excel file from which I need to copy the data and as it always remains the same,

    I tried the following code:

    Dim XLApp As Object, ws As Object
    Set XLApp = GetObject("myexcelsheetname").Application---->Gettiing a syntax error here
    XLApp.Sheets("Sheet 1").Shapes("Picture 3").Copy--Trouble here as well .(It says Subscript out of range.. but it WORKS WHEN I USE ACTIVESHEET instead of specifying the sheet name )
    Selection.Paste

    Looking forward for your help

    Regards
    Krishnan

  2. #2
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: Getobject()

    This code would go into an excel workbook - so it will copy a picture from (in this example) Sheet1 to a word document
    Sub CreateWordDoc()
        Dim wdApp As Object
        Dim wdDoc As Object
         Dim wdRng As Object
    Set wdApp = CreateObject("Word.Application")
    Set wdDoc = wdApp.Documents.Open("C:\temp\test.docx")
    Worksheets("Sheet1").Shapes("Picture 1").Copy
    wdApp.activedocument.Content.Paste
    wdApp.Visible = True
    End Sub
    Hope this helps.
    Anthony
    “Confidence never comes from having all the answers; it comes from being open to all the questions.”
    PS: Remember to mark your questions as Solved once you are satisfied and rate the answer(s) questions.”

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1