views:

369

answers:

1

Hi,

I am doing a small program to open an excel spreadsheet, update it then save it to a new file then close everything up.

It is all mostly working except when I use the SaveFileDialog the popup window is hidden behind the excel window, on the first attempt only (following attempts, triggered by a button, all work with the SaveFileDialog coming to the fore).

Does anyone know how I get this to happen on the 1st occurance too?

I also want to know if it is possible to not highlight the file name so that the user can append to the filename instead of directly overwriting it, by mistake, usually?

Here is the code I am using for the savefiledialog...

SaveFileDialog saver = new SaveFileDialog();
            saver.FileName = "test";
            saver.DefaultExt = "xls";
            saver.Filter = "Microsoft Office Excel Workbook |(*.xls*)";
            saver.CheckFileExists = false;
            saver.InitialDirectory = "c:\\George";

        if (saver.ShowDialog() == DialogResult.OK)
            //MessageBox.Show("Save Dialog launched");
            excelWorkbook.SaveAs(saver.FileName, Type.Missing, Type.Missing,Type.Missing,
            Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing,
            Type.Missing, Type.Missing, Type.Missing);

Many thanks, George

+1  A: 

IIRC you have to set OwnerWndProc to be the main window of the excel application.

Will
Ok thanks, I will see if I can find an example of using thins in C#. ;-)
George