PC Review


Reply
Thread Tools Rate Thread

C# Saves two copies of a file!

 
 
=?Utf-8?B?Sk0=?=
Guest
Posts: n/a
 
      23rd Mar 2005
Hi!

I've worked hard to get my data into Excel from a bunch of text files. I've
opened Excel and dumped the data in. I want to save the workbook/spreadsheet
but have not set a file name yet in the coding.

Running the below code I get a Dialog box that prompts for a file name and
path. You know the usual. I don't want this. I want to automate the entire
process. I want to create a filename that have MVC <Date>.xls.

If I cancel the dialog box I get an exception. If I put in a file name I
get my file (named as above) but also an additional file book1.xls for
example.

Is there a way to supress the dialog box and just save the file in the
naming convention that I want???

//Set default path and filename.
excel.DefaultFilePath = (@"C:\");
DateTime dtCurrTime = DateTime.Now;
string ExcelFile = "MVC " + dtCurrTime.ToShortDateString() + ".xls";
excel.Save(ExcelFile);
excel.Quit(); // Close Excel

Thanks JM
 
Reply With Quote
 
 
 
 
Dale Preston
Guest
Posts: n/a
 
      23rd Mar 2005
DisplayAlerts = false;

You should also use the SaveAs() method for files previously unsaved and set
Overwrite to true.

Dale Preston

"JM" <(E-Mail Removed)> wrote in message
news:6F82B53E-7F47-480B-A82D-(E-Mail Removed)...
> Hi!
>
> I've worked hard to get my data into Excel from a bunch of text files.

I've
> opened Excel and dumped the data in. I want to save the

workbook/spreadsheet
> but have not set a file name yet in the coding.
>
> Running the below code I get a Dialog box that prompts for a file name and
> path. You know the usual. I don't want this. I want to automate the

entire
> process. I want to create a filename that have MVC <Date>.xls.
>
> If I cancel the dialog box I get an exception. If I put in a file name I
> get my file (named as above) but also an additional file book1.xls for
> example.
>
> Is there a way to supress the dialog box and just save the file in the
> naming convention that I want???
>
> //Set default path and filename.
> excel.DefaultFilePath = (@"C:\");
> DateTime dtCurrTime = DateTime.Now;
> string ExcelFile = "MVC " + dtCurrTime.ToShortDateString() + ".xls";
> excel.Save(ExcelFile);
> excel.Quit(); // Close Excel
>
> Thanks JM



 
Reply With Quote
 
=?Utf-8?B?Sk0=?=
Guest
Posts: n/a
 
      23rd Mar 2005
Here is what I used. But the compiler complains

excel.ActiveWorkbook.SaveAs("c:\\MyWorkbook.xml",excel.XlFileFormat.xlXMLSpreadsheet,
Type.Missing, Type.Missing,Type.Missing, Type.Missing,
excel.XlSaveAsAccessMode.xlNoChange,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,Type.Missing);

excel.XlSaveAsAccessMode.xlNoChange & excel.XlFileFormat.xlXMLSpreadsheet

Any ideas as to what these constant values are? I actually want to save a
normal excel file too!

"Dale Preston" wrote:

> DisplayAlerts = false;
>
> You should also use the SaveAs() method for files previously unsaved and set
> Overwrite to true.
>
> Dale Preston
>
> "JM" <(E-Mail Removed)> wrote in message
> news:6F82B53E-7F47-480B-A82D-(E-Mail Removed)...
> > Hi!
> >
> > I've worked hard to get my data into Excel from a bunch of text files.

> I've
> > opened Excel and dumped the data in. I want to save the

> workbook/spreadsheet
> > but have not set a file name yet in the coding.
> >
> > Running the below code I get a Dialog box that prompts for a file name and
> > path. You know the usual. I don't want this. I want to automate the

> entire
> > process. I want to create a filename that have MVC <Date>.xls.
> >
> > If I cancel the dialog box I get an exception. If I put in a file name I
> > get my file (named as above) but also an additional file book1.xls for
> > example.
> >
> > Is there a way to supress the dialog box and just save the file in the
> > naming convention that I want???
> >
> > //Set default path and filename.
> > excel.DefaultFilePath = (@"C:\");
> > DateTime dtCurrTime = DateTime.Now;
> > string ExcelFile = "MVC " + dtCurrTime.ToShortDateString() + ".xls";
> > excel.Save(ExcelFile);
> > excel.Quit(); // Close Excel
> >
> > Thanks JM

>
>
>

 
Reply With Quote
 
=?Utf-8?B?Sk0=?=
Guest
Posts: n/a
 
      23rd Mar 2005
Never mind! I managed to figure out how to get the constants to work!

Here is an example!

string ExcelFile = "MVC " + dtCurrTime.ToShortDateString() + ".xls";

excel.ActiveWorkbook.SaveAs("c:\\" + ExcelFile,
Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, Type.Missing,
Type.Missing,Type.Missing, Type.Missing,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing);

"Dale Preston" wrote:

> DisplayAlerts = false;
>
> You should also use the SaveAs() method for files previously unsaved and set
> Overwrite to true.
>
> Dale Preston
>
> "JM" <(E-Mail Removed)> wrote in message
> news:6F82B53E-7F47-480B-A82D-(E-Mail Removed)...
> > Hi!
> >
> > I've worked hard to get my data into Excel from a bunch of text files.

> I've
> > opened Excel and dumped the data in. I want to save the

> workbook/spreadsheet
> > but have not set a file name yet in the coding.
> >
> > Running the below code I get a Dialog box that prompts for a file name and
> > path. You know the usual. I don't want this. I want to automate the

> entire
> > process. I want to create a filename that have MVC <Date>.xls.
> >
> > If I cancel the dialog box I get an exception. If I put in a file name I
> > get my file (named as above) but also an additional file book1.xls for
> > example.
> >
> > Is there a way to supress the dialog box and just save the file in the
> > naming convention that I want???
> >
> > //Set default path and filename.
> > excel.DefaultFilePath = (@"C:\");
> > DateTime dtCurrTime = DateTime.Now;
> > string ExcelFile = "MVC " + dtCurrTime.ToShortDateString() + ".xls";
> > excel.Save(ExcelFile);
> > excel.Quit(); // Close Excel
> >
> > Thanks JM

>
>
>

 
Reply With Quote
 
Dale Preston
Guest
Posts: n/a
 
      24th Mar 2005
I'm glad you got it. It saves me from digging deep into my archives for
when I last worked out saving Excel files from Visual Basic.

Dale

"JM" <(E-Mail Removed)> wrote in message
news:AD155196-6890-484B-9630-(E-Mail Removed)...
> Never mind! I managed to figure out how to get the constants to work!
>
> Here is an example!
>
> string ExcelFile = "MVC " + dtCurrTime.ToShortDateString() + ".xls";
>
> excel.ActiveWorkbook.SaveAs("c:\\" + ExcelFile,
> Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal,

Type.Missing,
> Type.Missing,Type.Missing, Type.Missing,
> Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,Type.Missing,
> Type.Missing, Type.Missing, Type.Missing, Type.Missing);
>
> "Dale Preston" wrote:
>
> > DisplayAlerts = false;
> >
> > You should also use the SaveAs() method for files previously unsaved and

set
> > Overwrite to true.
> >
> > Dale Preston
> >
> > "JM" <(E-Mail Removed)> wrote in message
> > news:6F82B53E-7F47-480B-A82D-(E-Mail Removed)...
> > > Hi!
> > >
> > > I've worked hard to get my data into Excel from a bunch of text files.

> > I've
> > > opened Excel and dumped the data in. I want to save the

> > workbook/spreadsheet
> > > but have not set a file name yet in the coding.
> > >
> > > Running the below code I get a Dialog box that prompts for a file name

and
> > > path. You know the usual. I don't want this. I want to automate the

> > entire
> > > process. I want to create a filename that have MVC <Date>.xls.
> > >
> > > If I cancel the dialog box I get an exception. If I put in a file

name I
> > > get my file (named as above) but also an additional file book1.xls for
> > > example.
> > >
> > > Is there a way to supress the dialog box and just save the file in the
> > > naming convention that I want???
> > >
> > > //Set default path and filename.
> > > excel.DefaultFilePath = (@"C:\");
> > > DateTime dtCurrTime = DateTime.Now;
> > > string ExcelFile = "MVC " + dtCurrTime.ToShortDateString() + ".xls";
> > > excel.Save(ExcelFile);
> > > excel.Quit(); // Close Excel
> > >
> > > Thanks JM

> >
> >
> >



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
network file copies/saves have dramatically slowed down Brad Pears Microsoft Windows 2000 Networking 3 28th Jan 2005 01:33 AM
Excel file saves as a temp file with numeric file name Rhema Microsoft Excel Misc 1 5th Feb 2004 02:57 AM
Win98 pc can't open file on WinXP pc until XP user opens and saves file. Dave Windows XP Networking 4 17th Dec 2003 07:54 PM
Word: Saves Multiple Copies of Same Document David Samuel Microsoft Word Document Management 1 28th Sep 2003 09:44 PM
Outlook saves multiple copies of messages Diana Clement Microsoft Outlook Discussion 0 8th Aug 2003 01:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:30 PM.