Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am totally new to C# and .net. I have the task of debugging an application which was written by someone who has long gone. The problem is as follows.

The application opens an excel workbook. If you edit the excel workbook and then save it from the application it works fine in every case I have tried except for one case. It does not work if a cell containing a formula cell is selected and then the bottom right-hand corner is selected and dragged to copy the formula into the cell below. It even works fine if I select the formula cell, do ctrl-C and then ctrl-V in another cell. It is just the dragging thing which seems to cause a problem.

The call is as follows:
currentwb.GetExcelWorkbook().SaveAs(
FileNameWithCxnID,
56,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Excel.XlSaveAsAccessMode.xlNoChange,
Missing.Value,
false,
Missing.Value,
Missing.Value,
Missing.Value);


I am totally stumped with this one right now. Can anyone give me any pointers to get me started.

Many thanks to anyone who can give even the tiniest hint!
Posted
Updated 25-Mar-13 8:00am
v3
Comments
Maciej Los 25-Mar-13 13:59pm    
Code, please, code!
Jackie Lloyd 25-Mar-13 14:01pm    
yeah, sorry, I just realised and was adding it as you asked! I don't know what else to put in.
Maciej Los 25-Mar-13 14:16pm    
Is that all your code???
Jackie Lloyd 26-Mar-13 5:20am    
There's a lot of code, and I am not allowed to copy the whole lot due to security. I am just starting to understand it all then should be able to post more relevant bits. I really just wondered if anyone knew any reason why the save would not work in this case but would in all the others, or could give me any leads to get me started. Is there anything different about saving a workbook when the click and drag has been performed. I have noticed that if I do the click and drag and then another operation afterwards e.g typing in a cell, then the save does work. So it must be that the click and drag leaves it in an odd state.

Well, I dont know exactly what you have to write, but I think the standard way Excel copy is the Cell.Value, and you want Excel.Formula. Thats what I do when that is needed anyway, but I dont know how to do it as you have specified.
 
Share this answer
 
I think that you are calling the SaveAs methods, there you can refer to the MSDN: http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook.saveas(v=vs.80).aspx[^]
 
Share this answer
 
Having looked into this, researched on the web etc I have found lots of cases where excel behaves in an odd, unhelpful manner. Workarounds seem to be suggested rather than logical solutions. So, I am going to create a macro which will cause an operation to be performed on the spreadsheet before every save. This will ensure that the click and drag operation is never the last operation before before every save.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900