Refreshing Power Pivot automatically - sql

I hope that you can help me.
That's my situation: daily I'm importing in Power Pivot some data through a query on a SQL database.
Actually every morning I open the Power Pivot and I refresh it for import the data of the previous day present in the database.
This action require 20 minutes because I have a lot of data to import.
I was wondering if there is a way to do this action during the night, maybe an automatic refresh, so that I can open the file in the morning and I alredy have the data of the previous day.
I hope that I was clear with my request, thanks in advice.

If the Excel workbook is on a machine that does not shut down, you can keep the workbook open and configure the query to automatically refresh ever x minutes.
Or you can keep the workbook open and run VBA code to refresh the query on a timer.
There are plenty of examples for VBA timers if you just care to search.
Or you can configure the queries to refresh automatically when the file is opened, then create a Windows Task Scheduler job to open the workbook at a specific time. Again, the computer running this must be turned on.
You see that there are many options and they are all well documented and just a short google search away.

Related

Speed up Excel 2016 Query Refresh Time when Importing Tables from Access 2016

I have a system where there are about 30 Excel 2016 templates that all pull prices for the items on each template from a single, master Access 2016 file. These are all located on a server that anyone with access may open. The templates are used to request specific items to be sent to a job site, while also tracking its price so it can be charged to that job. The goal of having a single master file with all the pricing is so that every time a price changes (which is fairly often), I don't have to update the price in every single template.
Right now, I have an Auto_Open module in each of these forms that refreshes the data from the Access file every time a copy of the template is opened. This ensures that the prices for the items that the project managers request for their job is updated every time they use the sheet. This usually completes in less than a second, and it updates all the information just fine. Here's the code:
Sub Auto_Open()
Application.ScreenUpdating = False
Sheets("Import Sheet").Unprotect Password:="secret"
Sheets("Import Sheet").Visible = True 'for some reason the data doesn't like to refresh unless the sheet is visible
ThisWorkbook.RefreshAll
Application.CalculateUntilAsyncQueriesDone 'ensures every connection refreshes
Sheets("Import Sheet").Visible = False
Sheets("Import Sheet").Unprotect Password:="secret"
Application.ScreenUpdating = True
End Sub
Recently, Microsoft put out an update to Excel that combines data imports and transformations into a new single section under the Data tab called "Get and Transform Data." Along with this update, new wizards were released to import data under the "Get Data" button in this section. The old "Legacy Wizards" are still available, which is what I was using and what has been working with the above code.
I looked for information on this new tab, but the only usable info was a Microsoft support web page, and it shows the old organization with separated sections, found here. So, I did my own testing, and I found the following differences:
It's possible to change how the data imports in the new wizard, i.e. I can delete rows and columns that I don't want. (This is particularly valuable for what I'm doing since some of the information for each item isn't used to calculate price, such as the supplier or the individual break down for shipping and the actual cost of the item).
I can't have a password on the new wizard, it doesn't let me open the Access file if it is password-protected. If someone has a solution to this one too, that'd be great.
The connection types are different. In the legacy wizards, the connection type is simply "Microsoft Access Database." However, the new wizards show the connection type as an "OLE DB Query."
Finally, the legacy wizard shows the import as a "connection," while the new wizard imports it as a "query."
My worry is that in the next version of Excel, the legacy wizards will no longer be available, so I would like to update to the new wizards. Further, it would also be beneficial to be able to only import specific rows and columns out of the Access file, which I can't do using the legacy wizards.
However, one of these template sheets imports 11 different tables, which ended up taking about 30 seconds to update when I tried opening a new worksheet based off of the template. This is way too long to be efficient or worth the benefits of the new wizard.
In the connection properties of the tables imported with the new wizard, there's a few options that I messed around with. First, I deleted my Auto_Open module and tried to use the "Refresh data when opening the file" option, this ended up taking a minute to update all of the tables, and it forced me to unlock the sheet, which I would strongly prefer to remain locked. Second, I tried the "Enable Fast Data Load" and "Enable background refresh," and I was able to get it down to 17 seconds, but that still is a pretty long time to wait every time you open a file. I would also prefer not to use background refresh, since the time spent on each sheet may not be enough to guarantee every price is updated, especially on some of the files with 10+ imported tables. Anyway, I attempted ever possible combination and I was only able to reduce the time to, on average, 20 seconds.
I guess the big questions of this post are:
How can I speed up the refresh time for the imported tables when I use the new wizards? And if I can't, how can I ensure that I will still have access to the legacy wizards?
Is it possible to lock an Access file while using the new wizards, and how do I do that?
The CAD technician that I work with is also communicating with some of his contacts within Microsoft to see if he can get any information about the future availability of the legacy wizards. If necessary, I can comment a few example files (with fake prices, obviously) so anyone can mess around with them.
Any help is greatly appreciated. Thank you!
If you can use .xlsm files, then you should use ADODB for connecting to the database.
Here is a good tutorial:
http://www.onlinepclearning.com/import-from-access-to-excel/
You can execute SQL statments to modify the database.
However if your database is password protected you will need to include that in the connection string,
and since it is very easy to crack protected vba projects, the password will not be safe at all.

Importing sharepoint data to excell via an existing connection through VBA

first time poster here
I am looking for a specific VBA solution and I just can't seem to google my way to the exact code I need - thus, I come here
I have an excel sheet with an existing connection to a sharepoint database. It calls this connection "toolbase"
I need code so that when this sheet loads up it fills its second sheet with a dump from that connection as if I pressed the Existing Connection > Connect > import table button. Its the only known connection to the sheet.
That's it - and for the love of my feeble VBA skills then I can't find the code for this. My boss just wants a list that refreshes itself every time the file loads. I know where to put the code - I just don't what to write.
Can someone help me out?
EDIT:
The closest I could find to what I think I need is something akin to this: https://support.microsoft.com/en-us/kb/306125
but that seems to be talking about extracting records - I need the whole table
Once the data connection has been made, just have ActiveWorkbook.RefreshAll assigned when the workbook opens.
You do need to show some research effort or attempted coding in future questions though (even if it's wrong) as this is not a free coding service (i let you off this time as the answer is a one liner ^^).

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!

MS ACCESS TransferSpreadsheet VBA to include extra information in import data

I am building an Access 2010 db which will store and query information relating to time spend by users in our team. Part of the reporting needs to include whether timesheets have been submitted on time.
The process is currently being managed in Excel but is becoming cumbersome due to the growing size of the consolidated data. In the current process, the flag on whether someone is late with their timesheet is applied manually.
Instead of manually adding a Yes / No value to the excel data, I wondered whether it was possible to set up separate TransferSpreadsheet processes in Access to upload the excel data (and attach them to separate command buttons) such that, depending on which one is executed, the import process adds a Yes or a No value to the last column in the data as it's being uploaded.
That way we can import the excel data for those who submitted their timesheets on time (and 'stamp' them Yes for being on time) and then any subsequently late submitted timesheet data can be imported later (and 'stamped' with a No).
I have spent several hours looking at online forums and instruction pages but cannot find anything close to what I am trying to achieve, hence the reason for posting this here.
This is just one of the options I am considering but my VBA skills are insufficient to establish whether such a process could be handled in VBA. All help appreciated. Thanks.
Solved this one myself with a bit of perseverance. Ended up running a few DoCmd.RunSQL commands to Alter / Delete / Insert the tables I had and used a 'join' table to load the data from excel and then ran a command to append the data from the 'join' table to the main table. I just invoke slightly different commands to update the table field based on whether the data has been submitted late or on time.

Running a VBA excel macro at a certain time

Trying to figure out the best way to kick off an excel macro at a certain time. I found a few suggestions, but I still have plenty of questions on the idea and was hoping you guys could provide some clarification.
What I am trying to do: I have live excel workbooks that are connected to my database. So at 11:30PM on the last day of every month I want to go into several excel workbooks (I have one for every vendor that we sell), enable the security and editing and refresh the connection so all of the information in the sheets is up to date. Lastly I would like to then save a copy of that file in a sub folder inside the current folder.
Run on time method:
Here is this run on time method that I found on ozgrid. My question is, I am assuming that excel would need to be running at the time in order to execute the method? If so what would be one way of opening up excel and refreshing a workbook to be saved?
Running excel on Windows Task Scheduler Windows Task Scheduler
Essentially this method is using an Excel Controller to run excel using VBS...Seems more promising than the run on time method but I am not very familiar with how an excel controller works or VBS, so any help or ideas on this one would be greatly appreciated.
Any input is greatly appreciated. If my ideas are way out in left field could you guys help point me in the right direction?
Thanks for all the help in advance!
Turn the problem around. Create a workbook with normal Excel query tools and have it load the result set of the query when the workbook is opened (You don't specify a version, but see Refresh an external data connection for Excel 2013).
Then, either create a view in the database that contains the results you require, or to materialise the result of a view into a staging table that is then read by the workbook.
Users can then open the workbook whenever they require data, and the current results will be available. A parametrised version of the query could then access a history table to older periods.
This way all data is only prepared when required, and is always available without the scheduling complexity.