Save as in Vb.net as excel object

benl

New Member
Joined
Apr 2, 2004
Messages
10
Hi,
Is anyone try to save excel object in vb.net? I have problem below:

I run the code below in vb.net and it have "error: 1004. Exception from HRESULT: 0x800A03EC"

xlsApp = New Excel.Application
xlsBook = xlsApp.Workbooks.Open(Filename:="D:\test.xls", UpdateLinks:=False, ReadOnly:=False)
xlsSheet = xlsBook.ActiveSheet()
xlsSheet.SaveAs(FileName:="D:\commaTEST", FileFormat:="xlCSV")


Thanks for your help...

Ben
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I think you have the wrong methods assigned to the wrong objects...try this...
Code:
xlsApp = New Excel.Application 
xlsBook = xlsApp.Workbooks.Open(Filename:="D:\test.xls", UpdateLinks:=False, ReadOnly:=False) 
xlsBook.SaveAs(FileName:="D:\commaTEST", FileFormat:="xlCSV")
 
Upvote 0
Thanks TommyGun,

But it is still give me that error! Some thing relate to "FileFormat"

if I dont use formatfile then it work but I want save as csv or tab format
xlsBook.SaveAs(FileName:="D:\commaTESTcsv.xls")

Cheers
Ben
 
Upvote 0
Hi,

The xlCSV shouldn't be enclosed in " marks as it's a constant. Try this instead:-

xlsBook.SaveAs(FileName:="D:\commaTEST", FileFormat:=Excel.XLFileFormat.xlCSV)

or alternatively:-

xlsBook.SaveAs(FileName:="D:\commaTEST", FileFormat:=6)

HTH
Dan
 
Upvote 0
Hello,

I am getting this error:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
When i try to save the file using xlbook.save it gets saved in mydocuments as Book1.xls

But when i try to save it as xlbook.saveas(here i pass value as mentioned by you).... it throws an exception which is mentioned above.

I am using Visual Studio 2010, working on framework 4.0 and language is Vb.Net..


Please help me out.

Thanks in advance.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top