Results 1 to 4 of 4

Thread: VB6 and Excel

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2002
    Posts
    19

    VB6 and Excel

    Hi all,

    I would like my VB program to open two Excel workbooks and copy the sheets from workbook1 to workbook2. Is there a way to do this?

    I tried to the Copy method, and Save, Add. But they do not work.
    All seem to point to working with one workbook only.

    I apologise if this query has already been answered, but I could not find any threads that could help.

    Many thanks for your time.

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

  3. #3
    Fanatic Member WorkHorse's Avatar
    Join Date
    Jul 2002
    Location
    Where you live.
    Posts
    591
    The Copy method should work.

    VB Code:
    1. Sub CopyExcelSheets()
    2.  
    3.     Dim objExcel As Object
    4.     Set objExcel = CreateObject("Excel.Application")
    5.    
    6.     With objExcel
    7.         ' Copy sheets from 2nd book to 1st book.
    8.         .Workbooks.Open filename:="C:\My Documents\A1.xls"
    9.         .Workbooks.Open filename:="C:\aaaWork\Queues1.xls"
    10.         .Workbooks(2).Sheets.Copy After:=.Workbooks(1).Sheets(.Workbooks(1).Sheets.Count)
    11.         .Workbooks(1).Save
    12.         .Quit
    13.     End With
    14.  
    15.     Set objExcel = Nothing
    16.  
    17. End Sub

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2002
    Posts
    19

    VB6 and Excel

    Many Thanks to both of you for your help.
    Will try both.

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