+ Reply to Thread
Results 1 to 4 of 4

Open Separate File, Copy Data and Paste Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    01-23-2009
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    50

    Open Separate File, Copy Data and Paste Macro

    Hi

    I have vba enable spreadsheet open C:\Workbook1.xlsm at "Sheet 1". I would like to write a macro for this file that open a second file, C:\Data.xlsx and copies "Sheet 2" A1:A20 and pastes the values only into Workbook 1, Sheet 1 A1:A20. I then need this macro to Close C:\Data.xlsx without saving.

    Any help would be greatly appreciated.

    Doug

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Open Separate File, Copy Data and Paste Macro

    Hi boohah
    something like
        Workbooks.Open Filename:="C:\Data.xlsx"
        Workbook("Data.xlsx").Sheets("Sheet2").Range("A1:D20").Copy Destination:=Workbooks("Workbook1.xlsm").Sheets("Sheet 1").Range("A1")
        Workbook("Data.xlsx").Close Saved = True
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Registered User
    Join Date
    01-23-2009
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    50

    Re: Open Separate File, Copy Data and Paste Macro

    Hi Pike

    That code is close but it doesnt paste the values only and I get a compile error when I run it saying that the sub or function is not defined.

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Open Separate File, Copy Data and Paste Macro

    Hi boohah
    Sub xtest()
    Workbooks.Open Filename:="C:\Data.xlsx"
        Workbooks("Data.xlsx").Sheets("Sheet2").Range("A1:D20").Copy (Workbooks("Workbook1.xlsm").Sheets("Sheet2").Range("A1"))
        Workbooks("Data.xlsx").Close Saved = True
    End Sub

+ 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