+ Reply to Thread
Results 1 to 4 of 4

Run Sql Queries in excel against database using Macro

  1. #1
    Registered User
    Join Date
    01-29-2014
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2

    Run Sql Queries in excel against database using Macro

    Hello- I'm new to this forum and need help with following badly..

    I have sql queries in spreadsheet column and which needs to run against Db2 database daily and then update the result back to spreadsheet. This is tedious process and could there be a way to create a a macro using VB which performs the following?

    1. connect to db2 database
    2. take the sql query one at a time from every row and then run against database
    3. Obtain the result and then update it back to last column of the spreadsheet.

  2. #2
    Forum Contributor
    Join Date
    12-26-2010
    Location
    Kansas City, Kansas
    MS-Off Ver
    Excel 2007
    Posts
    147

    Re: Run Sql Queries in excel against database using Macro

    I don't have db2 - but this might jump start you - CODE NOT TESTED


    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-29-2014
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Run Sql Queries in excel against database using Macro

    Thanks John. This is so much useful. I have started using this code and stuck with one problem. Basically i want to create a user form and then show the options to input user name, choose database, import spreadsheet which has sql and then submit . I have created the form and now i would like to show the form on first spreadsheet as static (i meant the form should be visible always like html page when the spreadsheet is opened ). i tried form.show option but it is not heping me. Any more ideas on this?

  4. #4
    Forum Contributor
    Join Date
    12-26-2010
    Location
    Kansas City, Kansas
    MS-Off Ver
    Excel 2007
    Posts
    147

    Re: Run Sql Queries in excel against database using Macro

    I'm NOT sure I can give you the BEST approach ..... (I don't work with forms alot)
    but the following seems to work. It uses the Workbook_Open Event as follows:



    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Can I use excel as a database with single-cell queries?
    By pine in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 06-19-2013, 10:28 PM
  2. Embedded Access queries in Excel - if the database moves, how to update queries?
    By Paul_mcc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-06-2012, 07:52 PM
  3. Replies: 2
    Last Post: 01-31-2012, 05:40 PM
  4. Macro retreiving data from SQL database through Access Linked tables and queries
    By Frederik_C in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-12-2008, 05:45 AM
  5. Executing queries stored in database in Excel
    By John B in forum Excel General
    Replies: 0
    Last Post: 12-15-2005, 05:15 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1