Results 1 to 2 of 2

Thread: [RESOLVED] Excel copy after probem

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Resolved [RESOLVED] Excel copy after probem

    I have some code which opens a source workbook and assigns it to a wbSource object and opens a destination workbook and assigns it to a wbDest object.

    My aim is then to copy some of the sheets from the source to destination workbook which I tried to do with this code but I get a "Copy method of Worksheet class failed" error message. Why???
    Code:
        For Each ws In wbSource.Worksheets
            If Left(ws.Name, 3) = "tab" Then
                wbSource.Sheets(ws.Name).Copy After:=Workbooks(wbDest.Name).Sheets.Count
            End If
        Next

  2. #2

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Excel copy after probem

    The workbooks need to be visible which they weren't. After that it's simple.

    Code:
    For Each ws In wbSource.Worksheets
            If Left(ws.Name, 3) = "tab" Then
                 ws.Copy After:=wbDest.Sheets(wbDest.Sheets.Count)
            End If
        Next

Posting Permissions

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



Click Here to Expand Forum to Full Width