Thank you so much I was having a problem with this for a long time. It makes much more sense now. I had required all SQL in the folder to be executed.
**I am new to Batch Files
Here is my Answer Example:-
Excel CommandButton Code:
Private Sub CommandButton1_Click()
Dim Username1 As String
Dim Password1 As String
Dim Server1 As String
Dim Database1 As String
Dim CommandString As String
Username1 = Cells(5, 6).Value
Password1 = Cells(6, 6).Value
Server1 = Cells(7, 6).Value
Database1 = Chr(34) + Cells(8, 6).Value + Chr(34)
CommandString = ThisWorkbook.Path & "\Place_SQL_Scripts_in_here\ExecuteAllSQLWithExcelParameters.bat" + " " + Username1 + " " + Password1 + " " + Server1 + " " + Database1
Call Shell("cmd.exe /c" & CommandString, vbNormalFocus)
End Sub
Batch File Code: @Mofi - I used a snippet of your code
@Echo off
goto :init
:init
setlocal
set Username1=%1
set Password1=%2
set Server1=%3
set Database1=%4
Echo.
Echo Executing All SQL Scripts in Folder "Place_SQL_Scripts_in_here"
Echo.
cd /D "%~dp0"
for %%G in (*.sql) do (echo [Executing %%G] & echo. & sqlcmd -S %Server1% -d %Database1% -U %Username1% -P %Password1% -i "%%G" & echo.)
Goto :End
:End
Echo Completed
Echo.
PAUSE
endlocal
goto :EOF
I had also received assistance from this post (How to execute Batch File while passing parameters from Excel)
Shell "test.bat"