1

i have created batch file to copy files from network drive to local.

.bat file:

SET username=%1
SET password=%2
net use "\\gesvij\toys\names" %password% /user:shop\%username%
:copy
Xcopy "\\gesvij\toys\names" "%appdata%\Microsoft\Templates" /S /E
IF ERRORLEVEL 0 goto disconnect
goto end
:disconnect 
net use "\\gesvij\toys\names" /delete
goto end
:end

i have tried the following code to execute the batch file in vba.

sub ok_click
dim un as string
dim pd as string
un = " " + un_text.value
pd = " " + pd_text.value

call shell("\\gesvij\toys\names\test.bat & un & pd")
end sub

now i have following question:

1) the batch file is not running properly from vba code. but the bat file is working properly when i run independently. 2) once the file copied in the local how do i disconnect the network path "\gesvij\toys\names" in the batch file

anyone please on this ?

1 Answer 1

2

Your not adding in the un and pd variables correctly. They need to be outside of the quotes like this:

"\\gesvij\toys\names\test.bat " & un & pd

Here is how I call a .bat file from VBA

Sub CreateReleasePart()
    Dim batPath As String: batPath = "C:\Users\sl\Desktop\"

    call Shell(Environ$("COMSPEC") & " /c " & batPath & "\myFile.bat", vbNormalFocus)
End Sub
Sign up to request clarification or add additional context in comments.

2 Comments

thanks much! its working fine. but when running vba code the cmd propmt is blinking and disappearing how do i stop it ? do you have any idea on it ?
The simpliest solution is to add the word pause at the place in your script (on it's own line) in which you want the screen left up. Try putting it at the end of your script. Please mark my answer as 'answered' if you have everything working now. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.