Question VS 2005 Problems Manipulating Excel From Console Application

SouthSideRob

New member
Joined
May 6, 2012
Messages
1
Programming Experience
10+
I'm setting up a console application that ... (I'm using late binding to manipulate Excel)

1. Executes a stored procedure that populates a SQL table for reporting purposes.

2. Opens an Excel Workbook.

3. Refreshes the Workbook.

4. Saves the Workbook.

5. Closes the Workbook.

6. Sends the Workbook as an attachmate in an e-mail using the SmtpClient class.

Now, steps 1 through 6 are inside of a loop as I would like to use the same workbook for all my report refreshes.

My perfect solution is to iterate this loop as many time as needed to have all my reports automatically sent via email as an attachmate.

The first time through the loop, it works perfectly, however, the 2nd time through the loop, I noticed when the application opens up the workbook, the workbook opens up as a read-only copy even though I properly closed the workbook prior to re-opening it.

I've tried to force the open as read/write but then, the 2nd time the workbook loads, an exception is thrown.

I'm on Windows 7 and I noticed that the folder properties has a read-only check box which I make sure is cleared before running the application but then when I stop/pause the application to inspect the folder properties, the check box is checked again. I'm not sure if this is why I'm having issues when I open up the Workbook a 2nd time or not.

If anybody knows how I can get past this. Please reply. It is greatly appreciated.
 
I'm a bit baffled here. Why do you need to loop 1-5 at all? If it's the same workbook, with the same values stored, all you need is to repeat step 6 for each email address (or better yet do it in a single mailing to multiple addresses with bcc if appropriate) surely? Or am I missing something?
 
Back
Top