2017-05-14 69 views
0

我从来没有很高兴能够使用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

+0

'的.xml“&[A1]'http://stackoverflow.com/documentation/excel-vba/1503/ranges-and-cells – Slai

+0

它的工作正是我想要的,谢谢@Robin Mackenzie 你是英雄:) – Archie

+0

我一定会检查这些文件。我相信他们会在未来帮助我。谢谢@Slai – Archie

回答

0

如果你知道细胞的表(如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 
相关问题