Excel to SQL via VBA

Hi friends,
While the following commands work great when launched from the T-SQL:
SELECT 'XLS' AS [Version], * 
  from OPENROWSET('Microsoft.ACE.OLEDB.12.0',
                  'Excel 12.0; Database=C:\Users\faraz.qureshi\Desktop\OldJunk\Book1.xls; HDR=YES; IMEX=1',
                  'SELECT * from [testdata]')
UNION ALL
SELECT 'XLSX', * 
  from OPENROWSET('Microsoft.ACE.OLEDB.12.0',
                  'Excel 12.0; Database=C:\Users\faraz.qureshi\Desktop\OldJunk\Book1.xlsx; HDR=YES; IMEX=1',
                  'SELECT * from [testdata]');
to import from Excel 2003 as well as Excel 2007+ both, what command could help me to achieve the same without interaction with SSMS, i.e. directly from Excel?
In other words, suppose I have a named range in excel testrange
how can I export the same in a new table named Test
in a database named Test_DB that exists on a server and instance named
MyComputer\SQL_FAQ.
Further, is it necessary to close
the Excel File first? Couldn't I export the selected range of Excel?
Thanks in advance.
Thanx in advance, Best Regards, Faraz A Qureshi

Hi FARAZ,
Regarding your description, Your requirement is about some programing approach to export excel to SQL Server, which is out of the queue of this forum.
According to "via VBA" in your question, I would you suggest you post your question to a dedicated
VBA forum. It is more appropriate and more experts will help you.
If you have any question, feel free to let me know.
Eric Zhang
TechNet Community Support

Similar Messages

  • Excel Sending Email via VBA - Suppressing the Warnings

    Hello everybody,
    I would be very appreciative if someone more knowledgeable than would help me out. I am building a VBA code in Excel that will send an Excel File as an attachment in an email to somebody using Outlook. I can get everything to work just fine except that a
    warning message pops up and it is quite irritation and negates the usefulness of the macro if I have to constantly click on [Allow].
    Any help with how to suppress the warning messages would be greatly appreciated! 
    Note: My company's IT will not let me download add-ins or programs not on their "safe" list.
    Also, I have included the important parts of my code below.
    Thanks!
    Eric
    Sub Email_Finance()
        Dim oApp As Object
        Dim oMail As Object
        Dim WB As Workbook
        Dim FileName As String
        Dim wSht As Worksheet
        Dim shtName As String
        Dim wsTab As Worksheet
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
        ' The section below goes to Outlook to create an email, fill in some details, and then emails it out.
        Set oApp = CreateObject("Outlook.Application")
        Set oMail = oApp.CreateItem(0)
        With oMail
            ' Uncomment the line below to hard code a recipient
            .To = "[email protected]"
            .Cc = "[email protected]"
            ' Uncomment the line below to hard code a subject
            .Subject = "G&A Monthly Report - Finance"
            ' Uncomment the lines below to hard code a body
            .body = "Dear Eric," & vbCrLf & vbCrLf & _
              "Please find attached the G&A report for this month. Please review and adjust accordingly. " & vbCrLf & vbCrLf & _
              "Thanks, Eric"
            .Attachments.Add WB.FullName
            .Display
            .Send
        End With

    See http://www.outlookcode.com/article.aspx?id=52 for the list of your options.
    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

  • The ForEach Loop Enumerator is Empty - SSIS Error when executing through CMD via VBA

    I am currently working on a SSIS package that is to be triggered through CMD via VBA (Access). All that the package does is read a bunch of files from a folder and upload them into a table in SQL Server. The tricky part comes is that this folder location from
    which the package is to read the files is dynamic.
    I figured out a way to make it dynamic, by using variables
    I have used the following variables:
    "Directory" against DIRECTORY in COLLECTION>>EXPRESSIONS in the ForEachfile Enumerator,
    "FilePath" (With Index 0) in the Variable Mappings
    PROBLEM : As the final link in the chain, I have used following to be triggered from VBA
    dtexec \f "C:\Desktop\SSISAppend.dtsx" /Set "\Package.Variables[User::Directory].Property[Value];C:\Desktop\AppendFiles"
    When I try to execute the package using the above command, it gives out the error
    Code : 0x8001C004
    Description: The For Each File Enumerator is empty. The For Each File enumerator did not find any files that meatched the file pattern, or the specified directory was empty.
    But, when I run the package from MS VisualStudio 2008, the package runs fine, takes the location of the file assigned to the variable "Directory". 
    All help is appreciated

    Where are you executing the package from? You're giving an aboslute path so this will work only if package as well as the folder is in the same machine from which you execute the above code. Otherwise you need to use UNC path.
    Another thing to check is what login is executing the command and you need to ensure it does have access to the directoty path as well as to the path where package resides.
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to set variables values via VBA.

    Anybody please help.
    How to set variables values via VBA in workbook. SAP Netweaver 2004s.

    Pass variable values with VBA and BI 7.0 funtions to Query
    At first a remark u2013 Iu2019ve read a lot of threads saying that passing values to a query can be done by using VBA code only. Iu2019ve tested it but Iu2019m not sufficient with the new BEX 7.0 API and therefore I use a mixture of BEX 7.0 funtionality and VBA. I create a BEX 7.0 design item button passing the values to a query u2013 I hide this button somewhere on the sheet or on a hidden sheet and I then raise the event to click the button from VBA code. Works fine and the maintenance is easier if something changes in the API in the future again.
    How to start:
    Switch to design mode in BEX Analyzer:
    Implement a BEX 7.0 design item u201Cbuttonu201D
    Click on the button to implement the properties
    Make the input for the commands
    data_provider = dataprovider_1
    cmd = process_variables
    subcmd = var_submit
    No comes the part with the variables u2013 Letu2019s assume a query has 4 variables but you only want to change 1 with the button u2013 an organizational unit for instance.
    Make a range somewhere in the excel with the following structure:
    Name    Index   Value
    VAR_NAME_1      1       Variablename
    VAR_VALUE_EXT_1 1       variablevalue
    Value should contain the name of your variable of course and u201Cvalueu201D the value of your variable
    Set a name for this range with EXCEL functionality but without the header:
    Back to the properties of the button: Insert the name of the range with the variables in the field Command Range:
    If you have more variables to process you can of course enhance your Filterrange!
    In the left upper Corner you have a name for your button:
    Now you can raise the button-click in vba like this:
    Application.Run "'" & ThisWorkbook.Name & "'!Sheet2.BUTTON_35_Click"
    regards, Lars

  • How to  send ALV output data into Excel sheet format via Mail to the user?

    Hi friends,
    I have a doubt ie,
    How to  send ALV output data into Excel sheet format via Mail to the user?
    regards
    Moosa

    Hi,
    Provide the output internal table to the objbin in the below FM
    Send Message
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
           EXPORTING
                document_data              = i_docdata
                put_in_outbox              = c_x
           TABLES
                packing_list               = i_objpack
                object_header              = i_objhead
                contents_bin               = i_objbin
                contents_txt               = i_objtxt
                receivers                  = i_reclist
    and specify the document type
      i_objpack-doc_type   = 'XLS'.
    and try.
    Regards,
    Nandha

  • Excel to SAP using VBA

    I would like to know if there is any possible way of exporting data from excelt to SAP using VBA code. I was going through one of the blogs /people/kathirvel.balakrishnan2/blog/2006/05/09/data-upload-into-sap-from-microsoft-excel-150-vba-part
    where in the data was exported from excel to SAP with the help of table name. Can the same be done using trasaction codes in SAP? If so, how.
    Also, I would like to know,if I can record a particular session(as how we do for recording a macro in excel) and use the same recorded session for other entries too.
    Thanks a lot in advance.
    Regards,
    P.Yogesh

    Hello,
    Whatz impossible ??
    Yes you can export the data from excel to SAP using VBA, but you need to create fome RFC in SAP as well that will handle the data you will send.
    1. Create a RFC function in R/3 that will read a file from specific location and perform the respective transaction.
    2. Create your excel file with respective file format and call the RFC function in SAP passing the parameters as file name and other required details.
    3. SAP coding for RFC will be a single time activity and then onwads you can just create excel file for upload and use VBA code to initiate the RFC call.
    Hope this make some sence. Tell me if you have more queries.
    Regards,
    Vishal
    Reward points.. if helpful

  • Can't send Excel 2007 File via Send To Email Option after Acrobat Install

    Normally, you can send an Excel 2007 file via email to someone by going to the Send option on the Excel file menu and choosing "Email." This will email an actual copy of the Excel 2007 file. However, since installing Adobe Acrobat  9 pro on my computer, this option, as well as the option to send to XPS are gone -- the only email option I have on that menu is to convert the file to a PDF and email it.
    It seems to me that Acrobat should ADD options to menus but not remove any! Does anyone know how I can get those missing options (especially the one to email the actual file itself) back? I've tried Googling up a solution, but to no avail so far.
    Thanks, in advance, for any help!
    Laura

    Thanks for taking the time to respond, Aditya!
    I saw that MS support article when I was trying to solve this issue on my own, but the solutions it proposes won't work for me -- I can't set Outlook as my email client (this is a work computer and we use Lotus Notes) and I can't muck around in the registry (again, this is a work computer). I know I can attach the Excel via the attach command in the email client, but the main thing is I don't understand why Acrobat has removed that option from the Excel menu. Also, it removed the Send to XPS option (which I don't really care about, but it bothers me because it shouldn't be deleting anything)!
    I even tried adding the Email command to the Quick Access Toolbar in Excel -- it let me add the button, but, when I click it, absolutely nothing happens.

  • How to set a sheet as Ad Hoc via VBA ...

    We keep trying to convert our existing workbooks for Smart View.
    As you can imagine this is a nightmare process but we keep trying ...
    There is some progress and we learnt a lot on the way but we still face some major issues - we find SV with VBA to be an unpredictible combo.
    Anyway ...
    In simple words I use a sequence of VBA SV API calls to create private connection (HypCreateConnection), to connect the sheet (HypConnect) and to retrieve data (HypRetrieveRange) - along the way I set up SV options and hide the Panel and the POV.
    All "by the book" - I wish such "a book" ever existed ... I mean the documentation is far from "in depth" ...
    The process works in c. 80% of cases (i.e. grids) but it fails on some (so far I found no correlation with anything else)
    I have tried and tried all sorts of tricks to debug it.
    It works with ALL grids in 1 in 20 tests but you can never predict when and why.
    So it can work but something somewhere causes the process to fail on some grids in most of the tests.
    I noticed one detail ...
    While the sheet gets connected and retrieved  with our process the Sheet Info still shows the sheet status as Empty ...
    When working from a blank worksheet and with the Panel open (i.e. NOT via VBA) one of the steps is to click on Ad Hoc Analysis button.
    It is unclear to me what exactly this one step does and it does not seem to be connecting or refreshing the grid.
    It seems it defines the grid to be an Ad Hoc one.
    Can the same be achieved programatically via VBA ?
    So far I have NOT found any equivalent API call.
    In desperation I am going to replace all HypRetrieveRange calls with HypMenuVRefresh call.
    Would it define the sheets as Adf Hoc ?
    I will find out ...
    Will it help with some odd grids ?
    Fingers crossed it will.
    Regards

    Hi Deiter,
    You can achieve this with below steps.. I am giving below steps considering you want
    to keep the condition type set as Obligatory always in your Pric Procedure
    -> Write a custome routine for "Requirement Routine" with the logic : When item category
        is ZAN, remove "Obligatory" check from KOMT1-KOBLI.
    -> Assign this routine to condition type ZZ00
    you are ready to go now.
    Why i am suggesting this...
    -> Industry best practise, to write minumum codes in user exits (in this case it will be sales user exit),
        as it increases system response time
    -> If we change someting in user exit, imagine, everytime you are creating a Sales Order, which does
        not call for this pricing procedure (with cond typ: ZZ00 ), still this part of user exit code written
        to check if item cat is ZAN or not will be called, so why to make system work more when
        actually not required
    Hope this helps !
    Regards
    Subhajit

  • BEx Analyzer - Edit Variables via VBA

    Hi all,
    I need to set the BEx variable values via VBA to change a selection for an input ready query.
    Is there a way to do that?
    Thanks a lot.
    Best regards,
    Christian.

    I heard that are some functions in BW 3.5 with getBex and setBex.
    But it isn`t supported for BW 7.0.

  • Accessing ribbon via vba ApplicationOptionsDialog

    hi,
    I am using microsoft access 2010 project (adp). I need to disable the file menu when I distribute the ade to
    clients.
    the backstage disable has no effect. my customized ribbon below. I only need to a way via vba to turn off the
    ApplicationOptionsDialog button! thanks!
    Code:
    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
    <ribbon startFromScratch="true">
    <tabs>
    <tab idMso="TabExternalData" visible="false" /> <tab idMso="TabCreate" visible="false" />
    <tab idMso="TabDatabaseTools" visible="false" /> <tab idMso="TabHomeAccess" visible="false" />
    </tabs>
    </ribbon>
    <backstage>
    <tab idMso="TabInfo" visible="false"/>
    <button idMso="FileSave" visible="false"/>
    <button idMso="SaveObjectAs" visible="false"/>
    <button idMso="FileOpenDatabase" visible="false"/>
    <button idMso="FileCloseDatabase" visible="false"/>
    <tab idMso="TabRecent" visible="false"/>
    <tab idMso="TabNew" visible="false"/>
    <tab idMso="TabPrint" visible="false"/>

    One thing to remember is that backstage commands ONLY work for the system wide ribbon. In other words, you cannot place backstage commands in a ribbon assigned to a given form/report.
    And as noted here, your schema definition needs to be changed from:
    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
    To
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    As a general rule, the older ribbon format will work, but not if you using new 2010 features. So backstage commands ONLY work in the application wide ribbon specified for startup. And you need to use the 2009 schema as opposed to 2006 schema.
    Regards,
    Albert D. Kallal (Access MVP)
    Edmonton, Alberta Canada

  • Password protect javascript via VBA

    Hey all,
    I need to execute javascript from my VBA code that will password protect my PDF file. I am currently using the method below:
    AForm.Fields.ExecuteThisJavaScript password_js
    where password_js is a variable with the javascript code in it. I have executed other javascript this way (adding text to the pdf) and it works fine.
    The javascript I am trying is from Applying PDF Password Security Using Acrobat JavaScript and works fine when run from within acrobat but it's not working through VBA. One thing I noticed is that when run from acrobat a save dialog pops up but through VBA nothing happens at all..
    Anyone know a simple way to do this? The password will be the same each time it is used - currently it is applied using the action wizard in acrobat but if I can run it via VBA after exporting the file to PDF it would be very nice!
    Thanks,
    Josh

    Using JavaScript within a PDF is a little different than processing within an external program or plug-in. You need to add more code to establish the PDF object and the objects within the PDF. You will need to download the Acrobat SDK and study the documentation for VBA.

  • Connecting Microsoft Access with Primavera via VBA

    I'm Primavera expert and Microsoft Access as well
    I want to know where to start to learn how can I establish a connection or session with Primavera from Microsoft Access via VBA.
    Thank you
    Emad

    Hello,
    I'm not familiar with Primavera P6 and Access. May be you should post the question in the
    Oracle Primavera forum.
    The following thread is about similar issue, you can try to use primavera SDK provider or ODBC connection:
    http://www.planningplanet.com/forums/planning-scheduling-programming-discussion/527878/primavera-p6-software-development-kit-sdk
    Regards,
    Fanny Liu
    Fanny Liu
    TechNet Community Support

  • Control BEx Analysis Grid context menu entries via VBA

    Hey Forum,
    I have kind of a tricky question for you. I want to control BEx Analysis Grid context menu entries via VBA, namely the Expand Hierarchy Node function when I right click on a Hierarchy node entry.
    Does anyone know how to access this function via VBA?
    I also thought about adding a BEx button and access it via VBA but I am lacking the correct Button Parameters to expand/collapse a hierarchy node.
    Anyone has a tipp for me?
    Thanks,
    R.

    Hello, DDrazdou and All too
    Did you have any information about requested function?
    I need to call binded transaction in R\3, and meanwhile, I just write wrapping functional module in the R\3, and making RFC call from VBA...
    It seems to work fine, but may be the better(standart) way is posible.
    with best regards, Alex.

  • Can't open Excel File manually after MS Project has opened it via VBA

    I was testing a section of code I got from a forum that opens a Excel Workbook via MS Project VBA so that I could use it to update a Excel Workbook that I have. The macro opens the Workbook as intended but the main problem I'm encountering is that
    after I've run the macro, saved and closed the Workbook again, I'm unable to open it manually either from Recents or directly from folder location. I'm using Project 2010 (non Server) and Excel 2010 - Windows 7.
    I'm also having trouble getting it to select "Sheet2" of the Workbook when it opens so I've Commented it out, but it would be a bonus if someone could shed some light on that one as well.
    Edit: I worked out how to select the Sheet...I've updated the code Below. 
    Sub OpenTest()
    Dim xlApp As Excel.Application
    Dim xlWkb As Excel.Workbook
    Set xlApp = CreateObject("Excel.Application")
    Set xlWkb = xlApp.Workbooks.Open_ ("C:\Users\myName\Desktop\Export Test1.xlsx")
    xlApp.Visible = True
    xlApp.Sheets("Sheet2").Select
    Set xlWkb = Nothing
    End Sub
    Thanks!
    Matt

    Matt,
    Actually your macro code works fine and I can re-open the file without problem.
    I don't recall asking in your other post but do you have SP2 installed for Project 2010? And, do you have SP2 installed for Office 2010, which will cover Excel? They are separate updates. It would also be a good idea to install the June 2013 cumulative update
    for Project 2010 as it was released after SP2 and it does fix some VBA issues as I recall.
    As I indicated, your code works fine on my PC which is also Project 2010, Office 2010 and Windows 7. Try this. After you run the macro and then save and close the workbook, does Excel also get closed automatically? If it does, (and it should), after you
    close the workbook, take a look at the applications manager to see which Windows applications are currently running. Does Excel still show up?
    John

  • Excel report and automatic format via VBA

    Hello,
    I made a report in MSY and created a Makro to format the Excel Sheet (the relevant data is copyied to another Workbook). Now I tried to run this Makro on startup so the user has no need to do this manually.
    This was done by the Workbook_Open() VBA command.
    But now there are several errors, because the makro was executed before the Workbook has been opened at all. For example, the error "the actual Workbook is in use" and something similar occured.
    To test the workbook_open() command, the following code produce 2 message boxes before the Excel Workbook is opened:
    Private Sub Workbook_Open()
        MsgBox "this should not happen"
    End Sub
    Even by saving the Makro in MSY, the message occured (so the makro must be executed).
    Is it possible to prevent the makro execution BEFORE the Worksheet is completely opened or is there a need to start the makro manually to format the Excel sheet?
    Thank you for your suggestions!
    Regards,
    Christian

    I would suggest something like:
    DBAdapter --> Bpel Process --> File Adapter --> write file to location (you can write in csv which can be imported into xls)
    Read Location --> FileAdapter --> Bpel Process --> Email Activity
    Regards,
    Anshul

Maybe you are looking for

  • ISE 1.2.1 Complaining about High latency - can´t figure out why.

    Hello!  my 2 node (16 core, 32 GB Ram, SAN) ISE installation on VMWARE is, complaining about High latency. I have about 250 Test clients connected, and the VMWARE guys can´t seem to find anything wrong. Is there anyway to get a more detailed test WHA

  • JMX Client/Server Classpath error

    Good morning, I have some aplication thats monitoring Websphere MQ queues. For this i'm use some MQ Jars, but its work fine. I have JMX Client/Server, for connect into MQ Server, my aplication use the MQ class MQConstants. My JMX connection work fine

  • Bold text in oracle

    how can we bold the text using oracle plsql. i have already done using the html tags in oracle.Please suggest some different solution. regards vishal

  • Getting %Error in authentication when using enable password via ACS 5.5

    Hey, I've been on a LAN that's been using ACS 4.1 and its been working fine.  Ive recently installed ACS 5.5 on a VM and Im attempting to get it to work.  I've changed the Tacacs IP to the new server and the secret key on this particular switch and I

  • [SOLVED] Adding users with command prompt

    I'm doing as the beginers guide says for adding non-sudo users to my installation. I'm using adduser to do this. For the bash bit is pressing enter to just have /bin/bash, which I assume is default ok? I also pressed enter to have default for user ID