-
Aug 6th, 2008, 09:13 AM
#1
Thread Starter
Frenzied Member
[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
-
Aug 6th, 2008, 09:46 AM
#2
Re: [2005] Excel Automation - Copy and paste using VB.Net Late Binding
-
Aug 6th, 2008, 09:58 AM
#3
Thread Starter
Frenzied Member
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
-
Aug 6th, 2008, 10:06 AM
#4
Addicted Member
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
-
Aug 6th, 2008, 11:24 AM
#5
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|