Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4584152
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:18:53+00:00 2026-05-21T21:18:53+00:00

I am trying to run a stored procedure from Excel. I know how to

  • 0

I am trying to run a stored procedure from Excel. I know how to do it without using dynamic dates but I need the date range to be dynamic.

Sub TestStoredProcedure()

    Dim CServer As String
    Dim CDatabase As String
    Dim CLogon As String
    Dim CPass As String
    Dim StartDate As Date
    Dim EndDate As Date
    Dim TStartDate As String
    Dim TEndDate As String

    CServer = "111111"         ' Your server name here
    CDatabase = "111111"    ' Your  database name here
    CLogon = "11111111"     ' your logon here
    CPass = "111111"             ' your  password here

    Dim Cmd1 As New ADODB.Command
    Dim rs As New ADODB.Recordset
    Dim intTemp As Integer

    Set Cmd1 = New ADODB.Command

    Cmd1.ActiveConnection = cn
    Cmd1.CommandText = "callstatisticsbyQ"
    Cmd1.CommandType = adCmdStoredProc

    Cmd1.Parameters.Refresh
    Cmd1.Parameters(0).Value = Worksheets("Sheet2").Range("A1")
    Cmd1.Parameters(1).Value = Worksheets("Sheet2").Range("A2")
    Cmd1.Parameters(2).Value = Worksheets("Sheet2").Range("A3")

    Set rs = Cmd1.Execute()

    rs.Open Cmd1
    Worksheets("Procedure Export").Range("A1").CopyFromRecordset rs

    Call DumpSP("prcGetData", "", "", Worksheets("Procedure Export").Range("A1"))

End Sub

I get an error saying something about user defined type not defined.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T21:18:54+00:00Added an answer on May 21, 2026 at 9:18 pm

    To use ADO you click Tools->references in the VBA IDE & tick “Microsoft ActiveX Data Objects” – preferably the highest version thereof.

    Additionally you use cn as the connection but its not defined in that sub (assuming its not global) & you will may need to Set Cmd1.ActiveConnection = cn.

    Also take a look at this, it defines the input (adParaminput) paramaters in advance rather than using .Refresh which is pretty inefficient (takes a trip to the server)

    Update for example:

    rem for create procedure callstatisticsbyQ (@i int, @c varchar(10)) as select 1234;
    
    Dim cn As ADODB.Connection
    Dim Cmd1 As ADODB.Command
    Dim rs As ADODB.Recordset
    
    Set cn = New ADODB.Connection
    Set Cmd1 = New ADODB.Command
    Set Cmd1 = New ADODB.Command
    
    cn.Open "Provider=SQLNCLI10;Server=1.2.3.4;Database=x;Uid=x; Pwd=x;"
    
    Set Cmd1.ActiveConnection = cn
    Cmd1.CommandText = "callstatisticsbyQ"
    Cmd1.CommandType = adCmdStoredProc
    Cmd1.Parameters.Append Cmd1.CreateParameter("p1", adInteger, adParamInput, , Worksheets("Sheet2").Range("A1"))
    Cmd1.Parameters.Append Cmd1.CreateParameter("p2", adVarChar, adParamInput, 20, Worksheets("Sheet2").Range("A2"))
    
    Set rs = Cmd1.Execute()
    MsgBox rs(0)
    
    rs.Close
    cn.Close
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to run the VS 2008 SP1 installer , but it says
I'm trying to run a batch file, as another user, from my web app.
I'm trying to run SQuirreL SQL. I've downloaded it and installed it, but when
I'm trying to run some commands in paralel, in background, using bash. Here's what
I'm trying to run some queries to get rid of XSS in our database
I'm trying to run a LINQ to SQL query that returns a result in
I'm trying to run a process and do stuff with its input, output and
I'm trying to run the Tomcat with JBoss Embedded jpa booking example. I run
I am trying to run xcopy that copies files excluding .obj, etc. What I
I'm trying to run an ASP.NET 2.0 application on an XP machine. As far

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.