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_
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.