使用shell赞扬VBA执行批处理文件无法正常工作 [英] executing batch file in vba using shell commend is not working

查看:825
本文介绍了使用shell赞扬VBA执行批处理文件无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建批处理文件,以从网络驱动器上的文件复制到本地。

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

.bat文件:

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

我曾尝试以下code来执行在VBA中的批处理文件。

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

现在我有以下问题:

1)批处理文件不会从VBA code正常运行。但bat文件工作正常,当我独立运行。
2)曾经在本地复制我如何断开网络路径中的文件\\ gesvij \\玩具\\名称的批处理文件

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

请人在这?

推荐答案

您不会在未添加和PD变量正确。他们需要的是外像这样报价:

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


下面是我如何调用从VBA .bat文件


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

这篇关于使用shell赞扬VBA执行批处理文件无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆