質問編集履歴
2
ソースコードの変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -27,7 +27,7 @@
|
|
27
27
|
Sub PicInsert()
|
28
28
|
|
29
29
|
Dim FolderPath As String
|
30
|
-
FolderPath = Range("A2").Value
|
30
|
+
FolderPath = Range("A2").Value 'A2には\Sampleまでのパスが入っている
|
31
31
|
Call FileSearch(FolderPath)
|
32
32
|
|
33
33
|
End Sub
|
1
Pasteプロシージャの追加、ソースコードの変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -5,8 +5,8 @@
|
|
5
5
|
|
6
6
|
### 実現したいこと
|
7
7
|
|
8
|
-
- [ ] Test配下にあるそれぞれのサブフォルダ内の画像をすべてシートに貼り付けたい。
|
8
|
+
- [ ] ~~Test配下にあるそれぞれのサブフォルダ内の画像をすべてシートに貼り付けたい。~~
|
9
|
-
- [ ] 貼り付けの際はサブフォルダごとの名前で新規シートを作成し貼り付けられるようにしたい。
|
9
|
+
- [ ] 貼り付けの際はサブフォルダごとの名前(Doubutu,Hito,Tabemono)で新規シートを作成し貼り付けられるようにしたい。
|
10
10
|
|
11
11
|
- [ ] 画像が入っているパスは以下の通り。Testの下にDoubutu,Hito,Tabemonoのフォルダがあり、その中に画像ファイルがそれぞれ3枚ずつ入っている。
|
12
12
|
![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-07-26/59df503a-64f9-4228-beed-06d75c7778fc.png)
|
@@ -15,8 +15,8 @@
|
|
15
15
|
![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-07-26/08f854e1-db6b-4112-a41d-fdc522faed33.png)
|
16
16
|
|
17
17
|
### 発生している問題・エラーメッセージ
|
18
|
-
- [ ] FSOを使った記述の仕方がわからない。
|
18
|
+
- [ ] ~~FSOを使った記述の仕方がわからない。~~
|
19
|
-
- [ ] 調べながら同じように記述するが実行できなくなってしまう。
|
19
|
+
- [ ] ~~調べながら同じように記述するが実行できなくなってしまう。~~
|
20
20
|
- [ ] サブフォルダの名前で新規シートを作るという記述の組み込み方がわからない。
|
21
21
|
- [ ] 再帰的な処理について流れがわからない。
|
22
22
|
|
@@ -25,27 +25,52 @@
|
|
25
25
|
|
26
26
|
```vba
|
27
27
|
Sub PicInsert()
|
28
|
-
Dim f As Variant
|
29
|
-
Dim Path As Variant
|
30
|
-
Dim FileName As Variant
|
31
28
|
|
32
|
-
|
29
|
+
Dim FolderPath As String
|
33
|
-
|
30
|
+
FolderPath = Range("A2").Value
|
34
|
-
|
35
|
-
With CreateObject("Scripting.FileSystemObject")
|
36
|
-
For Each f In .GetFolder(Path).SubFolders
|
37
|
-
Do Until FileName = ""
|
38
|
-
ActiveSheet.Pictures.Insert(f.Path).Select
|
39
|
-
|
31
|
+
Call FileSearch(FolderPath)
|
40
|
-
FileName = Dir()
|
41
|
-
Loop
|
42
|
-
Next f
|
43
|
-
End With
|
44
|
-
|
45
|
-
Call Paste() '画像の貼り付け方を決めているプロシージャ
|
46
32
|
|
47
33
|
End Sub
|
48
34
|
|
35
|
+
|
36
|
+
Sub FileSearch(FolderPath As String)
|
37
|
+
|
38
|
+
Dim FSO As Object, Folder As Variant
|
39
|
+
Dim ws As Worksheet
|
40
|
+
|
41
|
+
Set FSO = CreateObject("Scripting.FileSystemObject")
|
42
|
+
|
43
|
+
For Each Folder In FSO.GetFolder(FolderPath).SubFolders
|
44
|
+
Call FileSearch(Folder.Path)
|
45
|
+
Next Folder
|
46
|
+
|
47
|
+
For Each File In FSO.GetFolder(FolderPath).Files
|
48
|
+
'Debug.Print File.Path
|
49
|
+
ActiveSheet.Pictures.Insert File.Path
|
50
|
+
Next File
|
51
|
+
|
52
|
+
'貼り付け方の指定プロシージャ
|
53
|
+
Call Paste
|
54
|
+
|
55
|
+
End Sub
|
56
|
+
```
|
57
|
+
```vba
|
58
|
+
Sub Paste()
|
59
|
+
|
60
|
+
Dim Pic As Variant
|
61
|
+
Range("B3").Activate
|
62
|
+
For Each Pic In ActiveSheet.Shapes
|
63
|
+
Pic.Select
|
64
|
+
Pic.LockAspectRatio = msoTrue
|
65
|
+
|
66
|
+
Selection.ShapeRange.Top = ActiveCell.Top + 1
|
67
|
+
Selection.ShapeRange.Left = ActiveCell.Left
|
68
|
+
|
69
|
+
Pic.Height = 430
|
70
|
+
|
71
|
+
ActiveCell.Offset(25,0).Activate
|
72
|
+
Next Pic
|
73
|
+
End Sub
|
49
74
|
```
|
50
75
|
|
51
76
|
### 試したこと
|
@@ -54,3 +79,4 @@
|
|
54
79
|
- [ ] サブフォルダのパスの指定やコードの記述の仕方については一通り調べた。
|
55
80
|
|
56
81
|
|
82
|
+
|