Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

I need help working with Excel in VB.Net

Posted on 2013-07-01
2
Medium Priority
?
396 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:
Meir Rivkin earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

609 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