Import external .txt table to PowerPivot using VBA? - vba

I'd like to import some .txt tables to PowerPivot without clicking "From Other Sources" --> "Text File", but rather by running a VBA macro.
The idea is that there are several .txt tables, say
C:\Table1.txt
C:\Table2.txt
C:\Table3.txt
etc.
and to create a user form or similar so that a user can select which tables he needs, then VBA creates a single appended table in PowerPivot of the ones selected. I'd know how to do that if not for two parts:
1) How to import a table to PowerPivot from an external source (C:\) using a VBA command?
2) How to "append" those tables into one through VBA such that they wouldn't appear as different tables in PowerPivot, but rather as one table with always the same name?
I can find tangent questions and information, but no working examples of how to automate importing tables from external .txt sources (or .csv or .accdb for that matter) into a single PowerPivot table like this...
Thank you very much!

Power Query allows a GUI driven interface to do exactly what you want without VBA. You may want to consider that took instead, as it interfaces natively with Power Pivot and can be embedded in a hosted workbook, whereas the VBA solution could never work on SharePoint or Power BI.

Related

Is there a way to have a split, multi-user Access database that queries one shared excel file?

I ran into a multi-user related problem in my MS Access application.
I have a split database, with multiple front-ends and multiple back-ends. The file locations of the backend databases are stored in an Excel file. The front-end contains a combo box, of which the source is a query that reads the data from the excel file:
This enables the users to switch between the different be-databases.
SELECT XL.*
FROM (SELECT * FROM [Speicherorte BE_DB$] AS xlData IN 'Z:\LocationXYZ\Speicherort_BE_DB.XLSX'[Excel 12.0 Xml;HDR=yes;IMEX=0;ACCDB=Yes]) AS XL
ORDER BY gemeinde;
However, I noticed that doing so, this doesn't allow for multiple users at the same time.
Error: "External table is not in the expected format"
This error does not occur when only one person is using the application.
Does anyone have an idea on how to fix this? Maybe only query the excel file once upon startup and then have "static values" in the combo box for the rest of the time?
Thx in advance and best regards,
Michael

Link Data Models to multiple files

I created a file that imports multiple tables, and then I do several modifications and calculations with Power Pivot. The problem is that I want to use the final results, not only in that current workbook, but also in other workbooks.
So my question is, is there a way to link other excel files to that data model that I created and worked on?
Please note the data changes every day, so I am looking for a permanent connection.
Appreciate any help here.
if I understand you correctly you would like to access the PowerPivot model/measures that you have created in one xls file from within other xls files.
If so, the "core" vs. "thin" workbook approach might be what you are looking for. This approach works with Excel 2010 but not with Excel 2013 however and you will need a Sharepoint Server with PowerPivot for this to work.
The approach is described in Rob Collie's awesome PowerPivot blog:
http://www.powerpivotpro.com/2011/02/powerpivot-scheduled-refresh-pt-3-thin-workbooks/
and here:
https://pivotstreamllc.zendesk.com/hc/en-us/articles/201148566-Splitting-Workbooks-into-Core-Thin-Pairs
another option is to load all your data source in one Master workbook, then write back the result in the same workbook using Reverse Linked Tables.
Now you can use that Master workbook as your backend for all your reports.
or use PowerBI Desktop as your backend, officially it is not support but Excel can have a local connection to PowerBI desktop.
I put more details here
https://datamonkeysite.com/2016/11/13/thin-and-core-workbook-without-sharepoint-or-ssas/

Can Powerpivot be used to present data without pivoting it?

This isn't a coding question, so much as it is a functionality question.
I'm a bit new to Powerpivot and I'm attempting to use Powerpivot as a way to deliver reports to my team rather than SSRS because in our company, the only SSRS ReportServer I can use is officially "owned" by a team that is hostile to my team.
I have written numerous SQL ad-hoc queries that we are using for reports in SSRS, but been I've trying to migrate them to Powerpivot. For some of the reports, I've been able to paste the SQL query into the powerpivot window and make a pivottable out of these. However, I'd like to be able have some workbooks just contain the results of the query (they don't deal with numbers, as some of them are a data dump or a large collection of text strings), so that they look like the powerpivot window's dataset, but that they can be filtered, sorted, etc. Is this possible, or can I only use pivottables? I can't seem to find a way that I can just get Excel to directly display what is in the Powerpivot window without pivoting it - I know it is called Power*pivot* but because the PP window just shows the query results itself, I'm hoping there is a way to use it as an alternative to SSRS.
Also is there anyway to check if our Sharepoint server is capable of running Powerpivot so that I can deploy reports there for users to use without having Powerpivot installed on their computers other than by saving it to Sharepoint and seeing if a user can run it? If not, how difficult would it be to have an IT team update the SP server so that it can handle PP?
Any help is appreciated, as I'm in a position where I cannot contact IT or project management, and I can't raise any red flags with IT/BI/PM. Thank you very much for your time.
It sounds like you just want to get the results of your SQL query directly into an Excel spreadsheet, where you can use the Excel filter and sort capability. It doesn't appear that you want to use any of the functionality that PowerPivot provides, so you can achieve what you described by using an existing Excel component, Microsoft Query. It's a bit of a clunky old interface but it works. Here's some instructions to use:
In an Excel spreadsheet, click on the Data tab, select the "From Other Sources" button on the Get External Data area of the ribbon.
Select "From Microsoft Query"
On the "Choose Data Source" click OK to create a new data source
On the "Create new data source" window select the appropriate driver and database details for your data source
If using a SQL Server data source, don't select anything for the optional step 4 (select a default table).
Click OK to return to the Choose Data Source window, then OK again to select the new data source.
You're now prompted to choose columns for your query, but if you already have some SQL then click Cancel - this will display a prompt to continue editing in Microsoft Query - click Yes.
The Add Tables window pops up, click Close
You're now in the Microsoft Query interface. If you click on the SQL button, you can paste in your SQL. Click the Return Data button to run the query, the results will be displayed in an Excel worksheet.
Once this is set up, you just need to click "Refresh Data" on the Data tab to re-run the query and update the spreadsheet.

Bulk data insert in MS Access

I have an .mdb file, which is used as a data storage by one particular application. The application itself does not have tools to insert large amounts of data, and I need to insert around 300-400 generated records.
How can this be accomplished without using VB? (since I know nothing about it)
At first I thought that writing a procedure, but from what I can tell Access does not support procedures and functions (which ir really weird), only basic SQL statements.
Is exporting data into other DB like Postgre, writing and running a procedure there, and importing the data back into .mdb file possible? Or there are other solutions?
If you're looking to export data from a specific table then select that table and right click on it. A menu will appear that allows you to export the contents of that specific table. Choose the format (probably .csv or .txt for max flexibility) and then import it whereever and manipulate it accordingly.
If you want to reimport your results then choose from the File -> Get External Data -> Import menu and import your newly manipulated data. That should do it. Just make sure that the data columns align properly with the table your importing into. This shouldn't require any VBA. This advice is pertinent to Access 2003.

How to extract data from a database and populate a sheet in Excel

I am storing data in a backend database (PostgreSQL) which is running on a Linux machine. I want to be able to fetch data from the database, and populate a sheet in an excel workbook, so that I can carry out analysis in Excel.
It has been quite a while since I wrote anything in VBA, so I would appreciate some help (or links) in getting started. I would like to know the best way to approach this:
Pure VBA solution OR
Mixture of C# or other .Net language for data extraction logic and VBA for manipulating Excel objects (sheet data population etc)
Any ideas, tips, snippets and/or links that can help me get started on the twin objectives:
fetching data from a backend database (PostgreSQL) into Excel
populating a specified sheet in Excel with the columnar data retreived from the database
will be much appreciated.
If you are just trying to import data, Excel can do that without additional code. Just set up your windows client to connect to your postgreSQL server thru ODBC. (Here's one way guide to setting that part up: enter link description here
Then in Excel (Use a modern version, like 2007 or greater) from the "Data" tab, click on "Existing Connections" to connect to the ODBC connection you set up and pick the tables/data to import into excel. Once the spreadsheet has loaded the data, you can just click the "Refresh All" button to update the data.