Passing variables using excel macros in order to complete a sentence

后端 未结 1 1563
故里飘歌
故里飘歌 2021-01-28 10:11

I am new to excel macros.Please correct me if am asking anything silly.

I want to print the below CALL statement in excel sheet where SCHEMA_NAME, PROCEDURE_NAME, INPUT_

1条回答
  •  日久生厌
    2021-01-28 10:38

    You are on the right track. You can use contants as you did and you can use variables. The values of the variables can be taken from any source. N.b.: you can omit Concatenate and simply use &. (Note the spaces before and after.) E.g.:

    Dim s1 as String, s2 as String, sCommand as String
    
    s1 = Inputbox ("Enter schema name")
    s2 = Inputbox ("Enter procedure name")
    sCommand = "Call " & s1 & "." & s2 & "('INPUT_DATE','EXIT_DATE',STATUS)"
    

    Or you can take values from Excel or Word:

    Dim s1 as String, s2 as String, sCommand as String
    
    s1 = Cells(1, 1)       ' schema name
    s2 = Cells(2, 1)       ' procedure name
    sCommand = "Call " & s1 & "." & s2 & "('INPUT_DATE','EXIT_DATE',STATUS)"
    

    EDIT: To generate a list of commands as you need:

    Dim dFrom As Date, dTo As Date, d As Date
    Dim iStep As Long           ' day
    Dim i As Long
    
    dFrom = "2017-01-01"
    dTo =  "2017-06-30"
    iStep = 10              ' days
    i = 1                   ' start in column A
    
    For d = dFrom To dTo Step iStep
         sCommand = "Call " & s1 & "." & s2 & "(" & _
               Format(d, "yyyy-mm-dd") & "," & _
               Format(d + iStep - 1, "yyyy-mm-dd") & ",STATUS)"
         Cells(1, i).value = sCommand
         i = i + 1
    Next
    

    You can omit using sCommand and write the string directly to the cell, yet this way you can debug it easier.

    0 讨论(0)
提交回复
热议问题