VSTO Cached dataset becoming NULL - vsto

We have a VSTO Excel add-in that is capable of loading data by making web service calls. Once we get the data through web service response, we save it to a dataset and load it on the Excel sheet with the help of a list object. Now the dataset is always cached so that when the user opens the workbook next time, we need not make a web service call again to load data. It must load with the cached dataset.
The problem is, for some workbooks (Not all), the dataset is saving and loading properly after first save of the workbook. But, the same dataset is becoming null after second save onwards. The dataset has 4200+ records with 150+ columns. I would like to mention that after second save onwards, all other cached variables are having values. Only the cached dataset is null. Following points to better understand the problem.
Open the Excel template, load data via web service calls. (dataset is loaded now)
Save and close the workbook.
Reopen the same workbook. Dataset is still intact. Loads workbook properly.
Save and close the workbook.
Reopen the same workbook. Dataset is null. So data cannot be loaded to Excel. Existing excel rows are getting deleted as list object behaves as if it was opened for the first time.
Does anyone have any idea what could be wrong? We are using .NET framework 3.5/4.0 and Excel 2007. Excel 2010 does not create any problem.

Related

Access VBA: Copy single record to memory

I am converting an amalgamation of Excel VBA worksheets to an Access database. As seen too often, Excel was used as a database, and converting all data to Access Tables was very easy.
Now however comes getting the VBA forms and (object) modules to work again. I think I need to do this using the Recordset2 objects, however I want to be sure I am doing this the right way.
Always open the database read-only.
Copy, not link, one complete record to VBA application memory.
Use input data from user and data from record to CHANGE some data in this memory (record)... (or not if the user has no data)
Pass the record in memory, changed or unchanged, to the next step in
the process.
Am I on the right track with Recordset2?

How to save two workbooks as and mirror the connections that they contain

I need some conceptual help from those more experienced than me --
I know you guys usually like code but I have many pages of code on this project and my question is not regarding any code I have but rather how I might code something I have not been able to figure out.
So basically I have two workbooks whose main purpose is labor tracking. one is the control workbook that has all my code, the other is a workbook where reports are made by field workers. The reason the field workbook cannot have code is because it will be operated from an ipad which I believe cannot yet run VBA. I know how to establish the connections necessary, however for every project a new copy of both the workbooks need to be made. I already have functions that clear out, reset and save the main workbook however I am struggling with the connected workbook. I know how to save the connected workbook, but I was hoping to preserve the connections between the two old workbooks when I run the macro that saves them as and also mirror those connections between the new workbooks. Is this possible or will I need clear all connections and re establish them every time a new set of job books needs to be created?
===> EDIT: I believe that I need to embed the report book into the main book, but that still begs the question on how I save the embedded workbook as at the same time I save the main workbook as in order to create a new book with all the same connections

Excel data validation list from closed worksheet

I have two Excel 2016 worksheets in the same folder. One is shipment form and the other master database for shipment history. This file also holds the list of "active customers", which obviously changes over time.
When user is creating a new shipment from the shipment form template, I want the customer to be selected from a drop-down list rather than filled in manually. While I'm able to set up standard data validation for a cell, the problem is that the list is maintained in a different Excel file (which, as stated, is in the same folder).
I was also able to set up name reference and have the list from the other spreadsheet available, however I still have one major usability obstacle - it only works when the user has opened the other file, I want to avoid that and just have the user work with shipment form template.
I.e. I'm looking for Excel to fetch the data validation list from another file without forcing the user to keep it open. What are my chances here?
Thanks!
You can use Power Query to get the data from the other file, even if it is closed. Power Query can get the list into the current spreadsheet and you can build the data validation on the Power Query result. You can configure the query to be refreshed when the file is opened, or the user can refresh it manually.

Stored procedure running in the background?

Edited: Is it good practice to have a Store Procedure running retrieving data while the user keeps working while that data is compiled for them?
Old Question: I run a stored procedure to retrieve data from a server that takes about 10 - 15 minutes to complete. While running the stored procedure, my Excel workbook freezes until all the data has been returned. I might have an option to run this stored procedure in the background while allowing the Excel workbook to be workable. The idea is to give the user the possibility to work in the workbook while retrieving data instead of waiting 10 - 15 minutes just looking at the worksheet.
My question: I have never seen this idea before in any other application. I don't know if this means a good practice standard. Having the database loaded while working in the same workbook and when the data finishes alert the user that all the data has come through.
What do you guys think? Do you believe this could complicate something else?
I don't really like the idea but at lest the user wouldn't lose 10 - 15 minutes.
Thank you all :)
You need to create an instance of Excel application and run your stpred procedure there. In that case, your Excel application will still be available for the user, however I am expecting it to be slow. You have to modify your VBA code then to run in under a new instance of Excel application:
dim xlApp as Excel.Application
set xlApp=New Excel.Application
so here after to do your stuff you have to mention the application too since you have now more than one active application. For example to create a new workbook you would do:
xlApp.Workbooks.Add
I think you can probably open a new instance of Excel manually, then open your workbook that contains your VBA code using OPEN from FILE tab and then run your code, in that case the default Excel application will be available for the user to work. To open a new instance of Excel keep SHIFT key down and click on your Excel application icon (on your start menu or desktop etc, if you don't know where you can find it, simply go to Windows Start Menu and Search EXCEL)
Hope this helps!

VB - Automated Excel in Visual Studio 2010 - Selection Changed Question

I am currently writing an utility that takes two different sets of data from an excel document and sends it to two different web services. Each set of data has it's own button that sends the data to the web service. When the a button is clicked, the corresponding web service then returns data depending on the input values.
What I am trying to do is so that this utility can be distrobuted and used by a wide variety of people. What they are going to do is they are going to be synchronizing there particular cells of their own excel document to the corresponding cell in my utility. Using simple excel formulas. For example:
c:\temp\[book1.xls]sheet1'!a1
Now what I am trying to do is automatically "click" the button, or update, on my utility when the user links their cell to its corresponding cell on my utility.
I have tried the selection change event on my page. But it doesn't actually process until my utility is active, or clicked on.
Is there a way to make my utility automatically update? It would be especially awesome if somehow it did this while my utility was closed. So when the user opens it it is already filled with their information, and the outputs are correct.
The requirements:
you need to guarantee that when a user is using excel your app can collect the data. Your app may not be running at the time. You need the Worksheet_SelectionChange() event to fire automatically not just when your app is active.
Solution:
Basically in order to guarantee that the Worksheet_SelectionChange() is running all the time, and in order to guarantee that whenever the user opens an instance of excel you are able to collect and process the data/formulas entered into the particular target range address you need to wire up the selectionchange event inside of a VB.NET Excel COM Addin. There are several ways to do this, but since your using VB.NET your best off using the newest approach which is building a VSTO COM Addin.
There are numerous other questons available on how to best build a VSTO addin (some in C# some in VB.NET but all this information is exactly the same for both, just different syntax).
So you will need two projects. Your existing one, plus a Excel VSTO addin (which you can also do in VB.NET).
Now inside the selectionchange event you should make sure that your code handles the target range correctly; ie. make sure you check for non-contigious groups of ranges with a selection... A1:B1;D2:E2 and copy the data to your app. You may consider using a format such as xml to serialise the latest data from excel so that if your app is not open at the time, it can deserialise and read back the data stored for it the next time it is opened. I guess it really depends how your handling the data (i.e. is it for loading into a datagrid?) and whether you are going to do further processing and store it somewhere else later (in which case maybe you can put it straight into a database from the addin in excel).