Excel VBA:将单元格值复制到cmd
问题描述:
我从来没有很高兴能够使用VBA,我正在寻找一些建议或解决方案,为cmd添加单元格值。通过点击一个按钮Excel VBA:将单元格值复制到cmd
java -cp D:\Automation_Mobile.jar utils.Loop D:\MobileLogin.xml %value from cell here%
: 我希望我能在指定的命令
e.g的末尾添加我的循环值 与执行CMD。
我知道如何复制/粘贴单元格,工作表或文件,但我找不到如何添加一个单元格的值已经指定命令
Private Sub CommandButton2_Click()
Shell "CMD /K java -cp D:\Automation_Mobile.jar utils.Loop D:\MobileLogin.xml", vbNormalFocus
End Sub
我会很感激,如果有人能解释或者给我发任何解决方案,p
答
如果你知道细胞的表(如Sheet1
)及地址(例如A1
),你可以得到的值:
ThisWorkbook.Worksheets("Sheet1").Range("A1").Value
所以你R代码里面就变成了:
Option Explicit
Private Sub CommandButton2_Click()
Dim strBaseCmd As String
Dim rngParameter As Range
Dim strParameter As String
Dim strCmd As String
' base command
strBaseCmd = "CMD /K java -cp D:\Automation_Mobile.jar utils.Loop D:\MobileLogin.xml"
' get a cell from a sheet in this workbook
Set rngParameter = ThisWorkbook.Worksheets("Sheet1").Range("A1")
strParameter = rngParameter.Value
' add parameter to command
strCmd = strBaseCmd & " " & strParameter
' run command
Shell strCmd, vbNormalFocus
End Sub
'的.xml“&[A1]'http://stackoverflow.com/documentation/excel-vba/1503/ranges-and-cells – Slai
它的工作正是我想要的,谢谢@Robin Mackenzie 你是英雄:) – Archie
我一定会检查这些文件。我相信他们会在未来帮助我。谢谢@Slai – Archie