Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Feb 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA code for copying Sheet from One workbook to Another workbook

    Hi,
    I am new to VBA. I want to copy a sheet from one workbook to another workbook. I have following VBA code. I am getting "Run-time error '9': Subscript out of range. Please help.


    Sub Copy_sh()
    Dim SDrv As String
    Dim DDrv As String
    Dim Sfname As String
    Dim Dfname As String

    SDrv = "Y:\Main\" ' Source Drive
    Sfname = "Mailing Lists.xlsx"

    DDrv = "C:\Test\" ' Destination Drive
    Dfname = "Test 05FEB2014.xlsx"

    Workbooks.Open (SDrv & Sfname)
    Windows(SDrv & Sfname).Activate
    Workbooks(DDrv & Dfname).Sheets("List").Delete ' Delete the sheet if it already exists (Override the sheet)
    Sheets("List").Copy Before:=Workbooks(DDrv & Dfname).Sheets("List")

    Workbooks(SDrv & Sfname).Close
    Workbooks(DDrv & Dfname).Save
    Workbooks(DDrv & Dfname).Close

    End Sub

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    6,474
    Thanks
    211
    Thanked 848 Times in 780 Posts
    Thread closed duplicated in Spreadsheets.
    May the Forces of good computing be with you!

    RG

    VBA Rules!

    My Systems: Desktop Specs
    Laptop Specs


Posting Permissions

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