Results 1 to 5 of 5

Thread: [2005] Excel Automation - Copy and paste using VB.Net Late Binding

  1. #1

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    [2005] Excel Automation - Copy and paste using VB.Net Late Binding

    Hi there,

    I have a background worker which takes one excel file, opens it, copys a range of cells and pastes it into another excel file.

    I have been bashing my head against the wall now and cant seem to find a way round it?

    please advice:

    Code:
        Dim moApp1 As Object
            moApp1 = CreateObject("Excel.Application")
            moApp1.visible = False
            Dim oWB1 As Object
            Dim oSht1 As Object
            Dim PreviousWeek As String
            'MMR - 2008-07-09.xls
            PreviousWeek = fileName.Substring(0, fileName.Length - 14) & dateEnd.Year.ToString & "-" & FormatDate(dateEnd.AddDays(-7)) & "-" & FormatDay(dateEnd.AddDays(-7)) & ".xls"
            oWB1 = moApp.workbooks.open(PreviousWeek)
    
            oSht1 = oWB1.Sheets("Data").Select()
            oSht1.Range("A8:E44").Select() = True
            oSht1.Selection.Copy()
    
            oSht = oWB.sheets("Data").Select()
            oSht.Range("A8").Select()
            oWB.ActiveSheet.Paste()
    
            oWB1.Close(False)
    oWB1 and oSht1 is the source.
    oWB and oSht works fine, it is being used earlier.

    Cheers
    If you find my thread helpful, please remember to rate me

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [2005] Excel Automation - Copy and paste using VB.Net Late Binding

    So whats the problem?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: [2005] Excel Automation - Copy and paste using VB.Net Late Binding

    it stops at this line

    oSht1.Range("A8:E44").Select() = True

    Error is :
    {"Public member 'Range' on type 'Boolean' not found."}
    If you find my thread helpful, please remember to rate me

  4. #4
    Addicted Member
    Join Date
    Oct 2007
    Posts
    133

    Re: [2005] Excel Automation - Copy and paste using VB.Net Late Binding

    I know I had a project similar to this (although i cant find it to post you code) but i had a similar problem. I think, if you using VB.net and not VBA, you dont use the select method. As you arnt doing a macro, you dont need to Select it before you do something with it.
    VB version: Visual Studio 2008-Professional

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

    Re: [2005] Excel Automation - Copy and paste using VB.Net Late Binding

    Well hes trying to hightlight a range for copying. So select is correct but its used incorrect.

    Its a method and not a property so you cant assign any value to it.

    Code:
    oSht1.Range("A8:E44").Select()
    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

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