AFter modifying using c# and opening spreadsheet, it does not repaint

A

AP

Hi,

I'm trying to modify a spreadsheet programmatically using c#. My code runs
fine, but when I open the file by double clicking on it in explorer, the
window never repaints itself. If I open excel first, then open the spread
sheet it repaints fine. Any ideas why this would be happening? My code is
pasted below. I am using excel 2000.

private void button1_Click(object sender, System.EventArgs e) {

openFileDialog1.ShowDialog(this);

string file = openFileDialog1.FileName;

Excel.Application ea = new Excel.ApplicationClass();

Workbook wb = ea.Workbooks.Open(file,Type.Missing,Type.Missing,Type.Missing,

Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missin
g,Type.Missing,Type.Missing,Type.Missing);


Name n;

for (int i = 1; i<= wb.Names.Count ;i++) {

n = wb.Names.Item(i, Type.Missing, Type.Missing);

if (n.Name.StartsWith("Update")) {

n.RefersToRange.Value2 = "Updated from code: " + i++;


}

}

object oTrue = true;

wb.SaveAs("d:\\temp\\temp.xls",Type.Missing,Type.Missing,Type.Missing,Type.M
issing,Type.Missing,Excel.XlSaveAsAccessMode.xlNoChange,Type.Missing

,Type.Missing,Type.Missing,Type.Missing);

ea.Quit();

}



Thanks,

Adam
 
G

Guest

Adam

You might put a sub (not a function) in the ThisWorkBook section

Private Sub App_WorkbookOpen(ByVal Wb As Workbook
Wb.NameOfDialog.Repain
End Su

I haven't done this is Excel but I have in Word (sorry about VB) and this is how you start something on load

John H W
 
A

AP

I think I found the problem. For some reason ea.Quit was not actually
quitting the application. I suspect because I was using "save as" to save
the workbook and not saving or closing the original workbook, and then when
quit was called it was prompting to save changes but because the window was
not visible, the dialog box wasn't visible. Then when I reopened it by
double clicking it was in some weird state. This is my theory at least.


John H W said:
Adam:

You might put a sub (not a function) in the ThisWorkBook section:

Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
Wb.NameOfDialog.Repaint
End Sub

I haven't done this is Excel but I have in Word (sorry about VB) and this
is how you start something on load.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top