+ Reply to Thread
Results 1 to 2 of 2

Need help understanding this code. Upload range from excel to sql.

  1. #1
    Registered User
    Join Date
    03-19-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    4

    Question Need help understanding this code. Upload range from excel to sql.

    Hello All,

    I've benefited from lurking here for a while and figured I may as well join. I have a code template here I found to upload a range of data from excel into a sql server table. However, I don't see where any range is referenced. Since it is a basic template, I am sure I am supposed to add it somewhere along with the connection info to sql but I do not know where and could use some help. Say my range is A2:B40 and my connection name is 172.31.17.25 Epi. Where would this go in the code? I appreciate any help and am eager to learn more.

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Need help understanding this code. Upload range from excel to sql.

    You are meant to call the ExportRangeToSQL function from your own subroutine or function, specifying the sourceRange, conString and table parameters with your particular arguments. For example:

    Please Login or Register  to view this content.
    Note that the sourceRange argument is expected to contain the table column names in its first row.

    For the connection string, see http://www.connectionstrings.com/, or generate it yourself by using the Macro Recorder and doing a manual import data or database query from your database. The VBA code generated will include "ODBC;" or "OLEDB;" at the start of the connection string. Simply omit this part of the connection string from your own connection string.

    The only change I would make to the ExportRangeToSQL code is to temporarily comment out the On Error statement whilst testing because that line will hide any errors and make it very difficult to debug any errors.
    Last edited by Chippy; 03-19-2012 at 06:36 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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