question

Richardcollier-4099 avatar image
0 Votes"
Richardcollier-4099 asked JackJJun-MSFT commented

how to stop excel from appearing when opening in c# using Microsoft.Office.Interop.Excel;

using Microsoft.Office.Interop.Excel; i open the excel file using Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(location/filename);
when i use this the file opens and i would like for that not to happen and for the program to read the excel file in the background. I tried
lApp.Visible = false;
xlApp.DisplayAlerts = false;
before the Open statement but it still appears.

windows-formsoffice-excel-itprooffice-scripts-excel-dev
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi@Richardcollier-4099
As your issue is related to code development, but "office-excel-itpro" focuses more on general issue of Excel client.
To help you better, I would add the tag "office-scripts-excel-dev".
Thanks for your understandings.

0 Votes 0 ·

@Richardcollier-4099, Welcome to Microsoft Q&A, based on my test, the code lApp.Visible = false; will stop excel from appearing. Could you check it again? And I think that it may due to that you have opened a excel file and did not close it. You could use Task manager to check if you have any other excel files in the background processes.

I used the following code:


211585-image.png


0 Votes 0 ·
image.png (28.3 KiB)
Richardcollier-4099 avatar image
0 Votes"
Richardcollier-4099 answered JackJJun-MSFT commented

Hi I tried it again and still get the same result (excel opens for a second and closes)
private void button1_Click(object sender, EventArgs e)
{
Excel.Application spreadsheet = new Excel.Application();
spreadsheet.Visible = false;
Excel.Workbook excelWorkbook = spreadsheet.Workbooks.Open(location workbook);
excelWorkbook.Close();
spreadsheet.Quit();
}

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Richardcollier-4099, thanks for the feedback, What is your current OS version and Excel version?

0 Votes 0 ·
karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered

Usually one needs to make more of an effort for what they want out of Excel via automation rather than Open XML.

I invite you to examine the following code which I've used the pattern shown and never had your issue plus the code ensure (unless there is a runtime exception) all objects are released used.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Richardcollier-4099 avatar image
0 Votes"
Richardcollier-4099 answered JackJJun-MSFT commented

Sorry for the delay i believe my issue was not adding the visible=false till after i had the range done

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Richardcollier-4099, thanks for the response, let me confirm again, so has your problem been solved?

0 Votes 0 ·