回答編集履歴

1

サンプル追記

2017/07/13 12:16

投稿

otn
otn

スコア86281

test CHANGED
@@ -1,3 +1,59 @@
1
1
  cdは可能です。
2
2
 
3
3
  異なるドライブへの移動であれば、`cd /d `(もしくは`pushd`)とする必要がありますが、そのあたりは大丈夫でしょうか?
4
+
5
+
6
+
7
+ #VBAでのサンプルです
8
+
9
+ `cd`が効いているのが分かると思います。
10
+
11
+ ```
12
+
13
+ Sub foo()
14
+
15
+ Dim WSH, wExec
16
+
17
+ Dim cmd1 As String, cmd2 As String
18
+
19
+
20
+
21
+ Set WSH = CreateObject("WScript.Shell")
22
+
23
+
24
+
25
+ cmd1 = "cmd.exe /c dir"
26
+
27
+ cmd2 = "cmd.exe /c cd C:\ && dir"
28
+
29
+
30
+
31
+ WSH.CurrentDirectory = "C:\Users"
32
+
33
+
34
+
35
+ Set wExec = WSH.Exec(cmd1)
36
+
37
+ Do While wExec.Status = 0
38
+
39
+ DoEvents
40
+
41
+ Loop
42
+
43
+ Debug.Print wExec.StdOut.ReadAll
44
+
45
+
46
+
47
+ Set wExec = WSH.Exec(cmd2)
48
+
49
+ Do While wExec.Status = 0
50
+
51
+ DoEvents
52
+
53
+ Loop
54
+
55
+ Debug.Print wExec.StdOut.ReadAll
56
+
57
+ End Sub
58
+
59
+ ```