Solved

I need help working with Excel in VB.Net

Posted on 2013-07-01
2
387 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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now