I am trying to get VBA to access a SAS dataset for use in an excel spreadsheet, there appears to be a specific Method for doing this but I can't get it to work as it keeps giving me an error.
My code as it stands looks like
Sub GetData()
Dim sas as SASExcelAddIn
set sas=Application.COMAddIns.Item("SAS.ExcelAddIn").Object
Dim data as SASDataView
set data =sas.InsertDataFromSASFolder ("path", Sheet1.Range("A25"),25,True,"","",True)
End Sub
The value of Path is a unix path to the folder with the dataset in, I have tried specifying this both with the dataset and without and with the dataset without the file extension but I always get the error:
The only documentation I can find is https://documentation.sas.com/doc/en/amodg/8.3/p11y2jzgivsqw4n1ixw5jjf22obd.htm but it is not solving my issue.
My aim will be to automate this to allow the folder to be changed and the SAS datasets referenced to update to the new data with just a single input. Any ideas why this isn't working?
Thanks
The only thing I can think of, and I don't use VBA with SAS, is this statement: "The data source must be saved in the metadata" at the top. Let me propose an alternative if someone doesn't solve it. Consider using VSTO (C#), vs VBA, and read the SAS dataset using ODBC or OLEDB. Much, much simpler and easier to debug scenario. VSTO allows you to create anything in the ribbon and relies on interop to work with Excel.
Good luck on getting an answer. Consider an alternative if you hit the wall.
Related
I have an excel worksheet with 10 tabs.
For each tab, the data is structured as follows:
All tabs follow this same basic structure.
In Power BI, when I go to "Get Data", and then choose the .xlsx file, I get the following error:
Unable to connect
We encountered an error while trying to connect.
Details: "The input couldn't be recognized as a valid Excel document."
This is very frustrating and I don't know how such a simple task cannot be accomplished in Power BI.
Thank you.
Such alert could appear when you try to use Power BI connector on Excel file. It's understandable if the source file is corrupted and can't be opened in Excel. However, it looks strange if Excel opens the file in question and shows nothing wrong.
Based on our experience above is usually means what something is wrong with XML scheme of the Excel workbook.
Mushup trace (Data->New Query->Query Options->Diagnostics->Enable tracing) could give some additional information, but often not enough to find the reason.
We had two main scenarios
XML scheme is not complete
Usually if Excel file was generated by third-party tool. Such tool could generate quite limited XML scheme which is enough to open the file in Excel and to work with it, but not enough for Power BI connector. As an example, trace log shows
[DataFormat.Error] The input couldn't be recognized as a valid Excel document.\r\nStackTrace:\n…
…
[DataFormat.Error] We couldn't find a part named '/xl/sharedStrings.xml' in the Excel package.\r\nStackTrace:\n…
Such case is easy to fix – it's enough to open the file in Excel and save it (without any changes) – Excel is clever enough to fix the scheme. For the routine regular tasks we use poweshell script which does exactly the same in background.
There is the link within Excel file which is not recognizable as valid
Usually if Excel file is synced/kept with some cloud storage. One of the variants, wrong link could appear with copy/paste from another such file. That could be active link in one of the cells; or the link within conditional formatting formula; or even the link which actually isn't used by Excel but kept somewhere inside the scheme. For example, in one of the files I found in Data->Consolidate->All references the link like
'\drive.tresorit.com#7235\Tresors….[file.xlsx]Sheet'!$AC$6:$AC$357
on the file which was deleted long ago and isn't used, but for some strange reason the link was kept within the scheme.
Unfortunately for such case trace log doesn't give enough information to localize the issue, it looks like
[DataFormat.Error] The input couldn't be recognized as a valid Excel document.\r\nStackTrace:\n…
…
nExceptionType: System.UriFormatException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\r\nMessage: Invalid URI: The hostname could not be parsed.\r\nStackTrace:\n
Perhaps I have not enough knowledge for more straight forward localization of the problem, but the only way is to exclude Excel file parts one by one and check if the issue disappeared. Another way could be to unzip Excel file and check if wookbook.xml or sheetNN.xml have something suspicious inside.
I have a few SAS programs that I need to run from excel. The programs pull tables from SQL, perfom some calculations and give an output table that I would like to present in Excel. So I figured that it would be great to run everything in excel.
There are a few parameters in the code that need to be changed before running, so the best idea I had is to put the SAS scripts in cells on an excel sheet and change the variables with VBA.
My question is, is this achievable? Can I connect to SAS and do everything from excel?
I'm fairly good with VBA, starting to learn SAS, but I don't really know how to connect the two. Thank you for your help!
Yes it is possible , i did this in my work a week ago , SAS have an documentation here?
The link below can help you.
http://documentation.sas.com/api/docsets/itechwcdg/9.4/content/itechwcdg.pdf?locale=en
You can use ADODB to connect to , see here for the strings
https://www.connectionstrings.com/sas/
Your options are:
1) use VBA to connect to IOM, create a workspace, run your program.
This requires quite a bit of VBA, as well as the SAS Addin for MSO, and various components.
2) Run a Stored Process (STP) via point and click using the MSO addin
Again, this requires a desktop SAS Addin deployment, and isn't scriptable with VBA
3) Run a Stored Process as a web query
This is an excellent option - you don't need any special desktop installation, you can easily add (url) parameters, you can use it with / without VBA, and your output will render easily into your worksheet so long as you stream tab delimited data via the _webout fileref (without %stpxxx macros). It will also work with all versions of excel and SAS.
This approach is described here: https://www.rawsas.com/sas-as-a-service-an-easy-way-to-get-sas-into-excel-power-bi-and-000s-of-other-tools-languages/
trying to get some hands-on with golang. Currently I have an issue which I can fix using java but not with go.
Here is the issue. I have to read an excel file, and just get a Area Reference for example cells (Sheet1!A1:F6) and not the entire sheet.
This can be easily achieved using Apache Poi, but all the api's that go has do not have a way to get a range of cells. The golang library I am using is https://godoc.org/github.com/tealeg/xlsx . I would really appreciate if anyone has done this kind of work. Unfortunately I dont have a working code for go since I don't know the function I have to call. Other than go over all the columns and then ensure just get the ones I need.
It's my first question here so please be easy on me..
I'm trying to create an excel report from a dataset i've created in MS Access as part of a MS-Access based large project.
This project has to run on many machines and to avoid reference errors i use late-binding.
My problem is that when i try to create (from Access) a Timeline using the "Slicercaches.add2" method my code fires error "5". As a test i've created the timeline from Excel-vba and i found that if i use the "XlTimeline" constant it works, but if i use the "2" value not . Is there a way to use the Xltimeline constant inside Access-Vba without reference to excel libraries??
Thanx in advance
MF
First off, welcome to Stack Overflow. Without seeing your VBA code, answering your question would mostly be speculation. As a common practice, it is always beneficial to show the code you're working with (same concept as a picture is worth 1000 words). With that being said, working with Excel objects (or any other office application) requires that you import the necessary libraries. With the Excel library imported, you can essentially do anything to an excel file using the Excel object. Is there a particular reason you would like to refrain from using the Excel library?
My employer is considering installing OpenOffice.org's suite of Office products instead of using Microsoft Office. I've written several advanced applications in Access and Excel, and I'm trying to figure out what will and will not be compatable with OpenOffice.org.
Specifically, what do I need to do to have Calc (OpenOffice.org's version of Excel) read and execute VBA in macro's and tie macro events to button clicks?
Also of note, I'm using the MySQL Connector from within Excel to dynamically update data in the spreadsheet. What might I need to do to preserve data connectivity to our MySQL server?
Thanks
As far as I know, OOo Base can connect to an mdb file to the extent that it can open tables and queries. I think anything else - forms, reqportes, macros VBA and native - would need to be redeveloped.
I don't believe that OOo Calc can read or execute VBA: it has its own dialect of Basic, which has a variant syntax. It doesn't, as far as I can tell, support the concept of Class, for example. Some work appears to be occurring, however, see the OpenOffice Wiki for more information. Right now, I'd say you should be planning on a careful and complete rewrite.
Regarding the MySQL connector - I'd say that's the least of your worries...
On the plus side, you're likely to have real job security for a year or two while you get everything ported!
I recently discoverd go-oo which seems to be able to achieve your task.