![]() |
Locking a worksheet during the reading of it
Hello All!
I have an Excel 2003 workbook that contains Exchange Rates that is automatically updated by an external program. I have used VSTO 2005 to create an application that reads the updated Exchange Rates and saves them to a database using a webservice. The problem that I'm having is that when I'm reading my values, if any of the cells change, my application crashes. Is there a way to lock the values of the worksheet so that they don't get changed while I'm trying to read them? |
Locking a worksheet during the reading of it
Jason,
I don't know if your workbook is too big to save as a different workbook name and use the "copy" workbook as your reference. That way the external prg can update the original and you can work with the copy. FileCopy "C:\MyOriginal.xls" "C:\MyCopy.xls" You can kill the copy when you are done. Kill "C:\MyCopy.xls" -- Thx MSweetG222 "Jason" wrote: Hello All! I have an Excel 2003 workbook that contains Exchange Rates that is automatically updated by an external program. I have used VSTO 2005 to create an application that reads the updated Exchange Rates and saves them to a database using a webservice. The problem that I'm having is that when I'm reading my values, if any of the cells change, my application crashes. Is there a way to lock the values of the worksheet so that they don't get changed while I'm trying to read them? |
Locking a worksheet during the reading of it
Hi Jason,
From your description, it seems that you will have a VSTO 2005 enabled Excel Workbook which will be updated by an external program. Based on my experience, I did not recommend you do that because Excel works as a desktop application which did not works smoothly in the multiple user environment, the external program will be another user. For your scenario, I would like to recommend you use the Excel RTD feature which will update the data but not an external program. 289150 HOW TO: Set Up and Use the RTD Function in Excel 2002 http://support.microsoft.com/default...b;EN-US;289150 How To Create a RealTimeData Server for Excel http://support.microsoft.com/default...b;EN-US;285339 327215 Create a RealTimeData Server for Excel 2002 or later versions with Visual C++ http://support.microsoft.com/default...b;EN-US;327215 Building a Real-Time Data Server in Excel 2002 (Microsoft Excel 2002 Technical Articles) http://msdn.microsoft.com/library/de...us/dnexcl2k2/h tml/odc_xlrtdbuild.asp Best regards, Peter Huang Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
Locking a worksheet during the reading of it
Thanks for the reply MSweetG222
We thought of doing that, but the only problem is that the "external program" that I was refering too actually is a "plug-in" for excel...sorry for the mis-communication...I guess i meant that it's a third-party plug-in...(Actually, it's from Reuter's, I think it's called powerplus or something like that)...Anyways, the problem with saving the workbook, and then using the copy to read our values is that as soon as we open the workbook, the Reuter's stuff will automatically update and we have the same problem... "MSweetG222" wrote: Jason, I don't know if your workbook is too big to save as a different workbook name and use the "copy" workbook as your reference. That way the external prg can update the original and you can work with the copy. FileCopy "C:\MyOriginal.xls" "C:\MyCopy.xls" You can kill the copy when you are done. Kill "C:\MyCopy.xls" -- Thx MSweetG222 |
Locking a worksheet during the reading of it
Thanks for the response Peter, I'm not sure I explained my problem quite right...The "external program" that I'm refering too is actually a plug-in provided by Reuter's..and its what does the updating of the exchange rates...basically it updates the cells we specify with the exchange rates that we require. I then want to read those exchange rates, connect to my webservice, and update my database with those exchange rates... Does that make more sense? I'm not sure that the RTD is going to work in our situation... Jason ""Peter Huang" [MSFT]" wrote: Hi Jason, From your description, it seems that you will have a VSTO 2005 enabled Excel Workbook which will be updated by an external program. Based on my experience, I did not recommend you do that because Excel works as a desktop application which did not works smoothly in the multiple user environment, the external program will be another user. For your scenario, I would like to recommend you use the Excel RTD feature which will update the data but not an external program. 289150 HOW TO: Set Up and Use the RTD Function in Excel 2002 http://support.microsoft.com/default...b;EN-US;289150 How To Create a RealTimeData Server for Excel http://support.microsoft.com/default...b;EN-US;285339 327215 Create a RealTimeData Server for Excel 2002 or later versions with Visual C++ http://support.microsoft.com/default...b;EN-US;327215 Building a Real-Time Data Server in Excel 2002 (Microsoft Excel 2002 Technical Articles) http://msdn.microsoft.com/library/de...us/dnexcl2k2/h tml/odc_xlrtdbuild.asp Best regards, Peter Huang Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
Locking a worksheet during the reading of it
Hi Jason,
I understand the plugin is a COMAddin. From the scenario, it may be a race condition that the plugin is hoding the reference to certian cell/range and writing data and the VSTO code is try to hold and read the cell reference. This would need investigate the concrete ComAddin source about how it is implemented. So far I think you may try to enbrace the code that will cause the problem in the try/catch block to see if that will try to fix the problem. e.g. When you click the Button of the VSTO project and the excel will crash, then you may try to enbrace all the Button click event handler code in the try/catch. Also you may try to contact the Addin develop to see if there is a method to disable the addin code to refresh the data in the Excel Sheet temporarily. Based on my research, we can not disable a ComAddin temporarily with VBA code without restart the Excel application. A possible workaround is that you may try to save the current workbook as another workbook and then use the ADO/ADO.NET code to retrieve the Data in the Excel file that is not current loaded by Excel process so the com addin will not affect it. 311731 How To Query and Display Excel Data by Using ASP.NET, ADO.NET, and Visual Basic .NET http://support.microsoft.com/default...b;EN-US;311731 306572 How to query and display excel data by using ASP.NET, ADO.NET, and Visual C# .NET http://support.microsoft.com/default...b;EN-US;306572 316934 How To Use ADO.NET to Retrieve and Modify Records in an Excel Workbook With Visual Basic .NET http://support.microsoft.com/default...b;EN-US;316934 Best regards, Peter Huang Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
Locking a worksheet during the reading of it
Jason, try this
Option Explicit Option Base 1 '<<< variant array index starts at 1 Sub makeStableCopy() Range("A27") = "xxxx" ' <<< Reuters fills these in anywhere Range("Q100") = "yyyy" ' <<< Reuters fills these in anywhere Dim ReutersRates As Range Set ReutersRates = Range("A1:IP1000") '<<< set your active range With ThisWorkbook.Sheets("Prices") '<<< set your active sheet ReDim vArray(.UsedRange.Row, .UsedRange.Column) vArray = .UsedRange.Value End With Dim stableRates As Range Set stableRates = Range("A1001:A10000") '<<< set your destination range stableRates(1).Value = vArray(27, 1) '<<< the value from [A27] stableRates(2).Value = vArray(100, 17) '<<< the value from [Q100] 'these won't change no matter what Reuters does until you run this proc again. Debug.Print "range(A1001).value = "; Range("A1001").Value Debug.Print "range(A1002).value = "; Range("A1002").Value Debug.Print "stableRates(1).Value = "; stableRates(1).Value Debug.Print "stableRates(2).Value = "; stableRates(2).Value End Sub 'The shape of your destination array doesn't have to bear 'any relation to the shape of your input array as long as you 'index into the variant array with the same numbers as the 'cell coordinates of ReutersRates. Roy Jason wrote: Thanks for the response Peter, I'm not sure I explained my problem quite right...The "external program" that I'm refering too is actually a plug-in provided by Reuter's..and its what does the updating of the exchange rates...basically it updates the cells we specify with the exchange rates that we require. I then want to read those exchange rates, connect to my webservice, and update my database with those exchange rates... Does that make more sense? I'm not sure that the RTD is going to work in our situation... Jason ""Peter Huang" [MSFT]" wrote: Hi Jason, From your description, it seems that you will have a VSTO 2005 enabled Excel Workbook which will be updated by an external program. Based on my experience, I did not recommend you do that because Excel works as a desktop application which did not works smoothly in the multiple user environment, the external program will be another user. For your scenario, I would like to recommend you use the Excel RTD feature which will update the data but not an external program. 289150 HOW TO: Set Up and Use the RTD Function in Excel 2002 http://support.microsoft.com/default...b;EN-US;289150 How To Create a RealTimeData Server for Excel http://support.microsoft.com/default...b;EN-US;285339 327215 Create a RealTimeData Server for Excel 2002 or later versions with Visual C++ http://support.microsoft.com/default...b;EN-US;327215 Building a Real-Time Data Server in Excel 2002 (Microsoft Excel 2002 Technical Articles) http://msdn.microsoft.com/library/de...us/dnexcl2k2/h tml/odc_xlrtdbuild.asp Best regards, Peter Huang Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
All times are GMT +1. The time now is 02:33 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com