Serving the Quantitative Finance Community

 
User avatar
sllim
Topic Author
Posts: 0
Joined: September 24th, 2005, 5:20 am

Linking excel with sybase

January 6th, 2006, 6:35 am

Is it possible to link excel with sybase so that I can download data from sybase into excel spreadsheet (etc using vba)? If possible, how?
 
User avatar
MWG
Posts: 0
Joined: July 14th, 2002, 3:00 am

Linking excel with sybase

January 6th, 2006, 8:04 am

Yes you can... I am not an expert but the method that I use is via an ODBC and microsoft query.1.First get you ODBC link working independently on your pc it is available from Control Panel,Administrative Tools,Data Sources (ODBC)You may need a driver and some parameters to be defined on your pc.Normally the guy who installed sybase on the server can help here.2.Having got your database connection working , then access the database via Excel Data->Import External Data -> New database Querythen select the ODBC that you setup in Step 1.You can do step 2 via VB by call the corresponding functions . Just search the web there is lot of info on this stuff
 
User avatar
Rufus
Posts: 4
Joined: January 18th, 2002, 5:24 pm

Linking excel with sybase

January 6th, 2006, 11:41 am

easiest in vba:1. add microsoft activeX database object to your project (think that is what it's called)2. look up the connection and recordset objects in the object browser. The properties/methods for the connection object you need are connectionstring (or similar) and connect. 3. look up the correct connection strings for your database on msdn or google.4. you can get a recordset object from a connection using connection.execute()5. there are some utility methods for dumping a recordset to a spreadsheet I think.I think the above is mostly correct - but it's from memory so may be missing the odd detail as I'm on my MAC today. If you run into difficulties just repost.hope this helps!
 
User avatar
sloane

Linking excel with sybase

January 6th, 2006, 1:01 pm

sllim,The attached spreadsheet should set you on the way. It connects to an Oracle db via ado, iterating through a couple of (dodgy) SQL statements. You'll need to modify the code slightly to connect to sybase, (I think substituting "oraOLEDB.Oracle" with "Sybase ASE OLE DB Provider" should do it). Essentially though, it should give you an idea of how to query a db from excel with relative autonomy. I put together a function to handle populating the worksheets from the recordset, because I originally couldn't find a simple way of dumping the data directly from a recordset. There is probably a better way, but I haven't bothered to change it as this works for my purposes. It also allows you the option of printing the sql that produced the data at the bottom of the worksheet - always useful when you want to know how you got the data three months later!You'll also need to turn on the Activex data objects and ole db references under the Tools|References menu in the VBA menus.
 
User avatar
sloane

Linking excel with sybase

January 6th, 2006, 1:13 pm

No idea where the attachment went. I've put in the VBA code instead. You'll need to change the connection details dbCon etc, that refer to wks.cells(5,3) etc, and also change the checkWKS(0) and checkWKS(1) strings to sheet names in your worksheet. It's all pretty obvious.
 
User avatar
sllim
Topic Author
Posts: 0
Joined: September 24th, 2005, 5:20 am

Linking excel with sybase

January 9th, 2006, 12:49 am

Thanks for you guys' help. Will try out all the suggestions.