[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
Re: [2005] Excel Automation - Copy and paste using VB.Net Late Binding
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."}
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.
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()