Results 1 to 4 of 4

Thread: Sheets Failing to Copy

  1. #1

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Sheets Failing to Copy

    I am running into a problem when trying to copy multiplesheets in a row in excel. The copy works if its only 1 or 2 sheets but anything over 2 copies in a row it fails, and I dont get an error.

    I am using this code...

    VB Code:
    1. Set oSheet = oBook.Worksheets(oBook.Sheets(oBook.Sheets.Count).Name)
    2. lngSheetCount = oBook.Sheets.Count
    3.        
    4. 'Copy inital last sheet into new sheet
    5.  oExcel.ActiveWorkbook.Sheets(lngSheetCount).Copy _
    6. After:=oExcel.ActiveWorkbook.Sheets(lngSheetCount)
    7. Set oSheet = oExcel.ActiveSheet
    8. 'Rename the worksheet
    9. oSheet.Name = Firms.Item(clc)

    I was wondering if anyone else had run into this issue, I have tried placing DoEvents in some places to try to pass control back to windows so it could finish the copy but it doesnt seem to work.

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Sheets Failing to Copy

    Moved to Office Development

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Sheets Failing to Copy

    It could be because of the use of the "ActiveWorkbook" object instead of the Workbooks collection.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Sheets Failing to Copy

    I think this may be what you want to do (???):
    Code:
    Sheets(Array("Sheet5", "Sheet3", "Sheet1")).Copy
    I can't figure out how your code is trying to work with multiple sheets (???).
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

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