回答編集履歴

3

コード修正

2021/11/02 17:38

投稿

hatena19
hatena19

スコア34075

test CHANGED
@@ -34,7 +34,7 @@
34
34
 
35
35
  Do While Len(pdf_path_dir) > 0
36
36
 
37
- pdf_dic(Replace(pdf_path_dir, ".pdf", "")) = "" '
37
+ pdf_dic(Replace(pdf_path_dir, ".pdf", "")) = ""
38
38
 
39
39
  pdf_path_dir = Dir()
40
40
 
@@ -84,8 +84,6 @@
84
84
 
85
85
 
86
86
 
87
-
88
-
89
87
  Debug.Print "PDFのみに存在: " & Join(pdf_dic.Keys)
90
88
 
91
89
  Debug.Print "CSVのみに存在: " & Join(csv_dic.Keys)

2

コード修正

2021/11/02 17:38

投稿

hatena19
hatena19

スコア34075

test CHANGED
@@ -34,7 +34,7 @@
34
34
 
35
35
  Do While Len(pdf_path_dir) > 0
36
36
 
37
- pdf_dic(pdf_path_dir) = "" '
37
+ pdf_dic(Replace(pdf_path_dir, ".pdf", "")) = "" '
38
38
 
39
39
  pdf_path_dir = Dir()
40
40
 
@@ -52,9 +52,9 @@
52
52
 
53
53
 
54
54
 
55
- csv_name = Dir(src_path & "*csv")
55
+ csv_name = Dir(src_path & "*.csv")
56
56
 
57
- Set csv_ws = Workbooks.Open(Filename:=src_path & csv_name)
57
+ Set csv_ws = Workbooks.Open(Filename:=src_path & csv_name).Sheets(1)
58
58
 
59
59
 
60
60
 
@@ -84,10 +84,14 @@
84
84
 
85
85
 
86
86
 
87
+
88
+
87
89
  Debug.Print "PDFのみに存在: " & Join(pdf_dic.Keys)
88
90
 
89
91
  Debug.Print "CSVのみに存在: " & Join(csv_dic.Keys)
90
92
 
93
+
94
+
91
95
  End Sub
92
96
 
93
97
  ```

1

コード追記

2021/11/02 15:23

投稿

hatena19
hatena19

スコア34075

test CHANGED
@@ -3,3 +3,91 @@
3
3
 
4
4
 
5
5
  [Dictionary(ディクショナリー)連想配列の使い方について|VBA技術解説](https://excel-ubara.com/excelvba4/EXCEL216.html)
6
+
7
+
8
+
9
+ ---
10
+
11
+
12
+
13
+ コード例
14
+
15
+ ```vba
16
+
17
+ Sub get_diff()
18
+
19
+ Dim pdf_dic As New Dictionary 'Microsoft Scripting Runtime参照設定必須
20
+
21
+ Dim csv_dic As New Dictionary
22
+
23
+
24
+
25
+ Dim src_path As String
26
+
27
+ Dim pdf_path_dir As String
28
+
29
+ src_path = ThisWorkbook.Path & "\src\"
30
+
31
+ pdf_path_dir = Dir(src_path & "*.pdf")
32
+
33
+
34
+
35
+ Do While Len(pdf_path_dir) > 0
36
+
37
+ pdf_dic(pdf_path_dir) = "" '
38
+
39
+ pdf_path_dir = Dir()
40
+
41
+ Loop
42
+
43
+
44
+
45
+ Dim csv_name As String
46
+
47
+ Dim csv_ws As Worksheet
48
+
49
+ Dim get_col As Integer
50
+
51
+ Dim i As Long
52
+
53
+
54
+
55
+ csv_name = Dir(src_path & "*csv")
56
+
57
+ Set csv_ws = Workbooks.Open(Filename:=src_path & csv_name)
58
+
59
+
60
+
61
+ get_col = csv_ws.Range("1:1").Find("特定の値").Column
62
+
63
+ i = 2
64
+
65
+ Do While csv_ws.Cells(i, get_col) <> ""
66
+
67
+ Dim buf As String
68
+
69
+ buf = Replace(csv_ws.Cells(i, get_col).Value, " ", "")
70
+
71
+ If pdf_dic.Exists(buf) Then
72
+
73
+ pdf_dic.Remove buf 'csvと重複したら削除
74
+
75
+ Else
76
+
77
+ csv_dic(buf) = "" 'pdfにない値を格納
78
+
79
+ End If
80
+
81
+ i = i + 1
82
+
83
+ Loop
84
+
85
+
86
+
87
+ Debug.Print "PDFのみに存在: " & Join(pdf_dic.Keys)
88
+
89
+ Debug.Print "CSVのみに存在: " & Join(csv_dic.Keys)
90
+
91
+ End Sub
92
+
93
+ ```