Solved

I need help working with Excel in VB.Net

Posted on 2013-07-01
2
391 Views
Last Modified: 2013-07-02
Hi Experts,
I have the following code which generates and saves an Excel spreadsheet from my VB.Net application.

1) How can I make it so Excel saves the file without prompting me that there already is an Existing file with the same name (I want it to overwrite the file if it already exists)?
2) How can I open the file (i.e. make it visible after it has been saved)?


        Dim xlApp As Excel.Application
        Dim xlWorkBook As Excel.Workbook
        Dim xlWorkSheet As Excel.Worksheet
        Dim misValue As Object = System.Reflection.Missing.Value

        xlApp = New Excel.Application
        xlWorkBook = xlApp.Workbooks.Add(misValue)
        xlWorkSheet = xlWorkBook.Sheets("sheet1")

		'SOME DATA PROCESSING ...
		
        xlWorkBook.SaveAs("c:\Transactions.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, _
        Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue)
        xlWorkBook.Close(True, misValue, misValue)
        xlApp.Quit()

Open in new window


Thanks in advance,
mrotor
0
Comment
Question by:mainrotor
2 Comments
 
LVL 5

Expert Comment

by:Jason Schlueter
ID: 39291750
Maybe something like this?

1) System.IO.File.Delete(filename) before save.
2) myProcess = Process.Start("excel.exe /r book1.xlsx");
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39292278
to save the file without prompt use:
xlApp.DisplayAlerts = false;

Open in new window


to open the file after save:
Process.Start("c:\Transactions.xls");

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Studios 1 78
Generate Numbers in JQuery file 11 66
Optimize the query 5 43
Install IIS7.5 on Windows Sever 2012 R2 4 24
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question