回答編集履歴

2

追記

2021/06/09 01:14

投稿

jinoji
jinoji

スコア4592

test CHANGED
@@ -126,6 +126,46 @@
126
126
 
127
127
  Sub macro2()
128
128
 
129
+
130
+
131
+ Dim i
132
+
133
+ ReDim wsNames(1 To Worksheets.Count)
134
+
135
+ For i = 1 To Worksheets.Count
136
+
137
+ wsNames(i) = Worksheets(i).Name
138
+
139
+ Next
140
+
141
+
142
+
143
+ Dim v, ary
144
+
145
+ For Each v In Array("100", "200", "300")
146
+
147
+ ary = Filter(wsNames, v)
148
+
149
+ If UBound(ary) > -1 Then
150
+
151
+ Worksheets(ary).Select
152
+
153
+ ActiveSheet.ExportAsFixedFormat Type:=0, Filename:=v & ".pdf"
154
+
155
+ End If
156
+
157
+ Next
158
+
159
+
160
+
161
+ End Sub
162
+
163
+ ```
164
+
165
+ ```VBA
166
+
167
+ Sub macro3()
168
+
129
169
 
130
170
 
131
171
  Dim dic 'As Scripting.Dictionary
@@ -134,29 +174,25 @@
134
174
 
135
175
 
136
176
 
137
- Dim ws As Worksheet
177
+ Dim ws As Worksheet, tCode As String
138
178
 
139
179
  For Each ws In Sheets
140
180
 
141
- dic.Add ws.Name, ws
181
+ tCode = Left(ws.Name, 3)
182
+
142
-
183
+ dic(tCode) = dic(tCode) & " " & ws.Name
184
+
143
- Next
185
+ Next
144
-
145
-
146
-
186
+
187
+
188
+
147
- Dim v, ary
189
+ Dim k
148
-
149
- For Each v In Array("100", "200", "300")
190
+
150
-
151
- ary = Filter(dic.Keys, v)
152
-
153
- If UBound(ary) > -1 Then
191
+ For Each k In dic
154
-
192
+
155
- Worksheets(ary).Select
193
+ Worksheets(Split(Trim(dic(k)))).Select
156
-
194
+
157
- ActiveSheet.ExportAsFixedFormat Type:=0, Filename:=v & ".pdf"
195
+ ActiveSheet.ExportAsFixedFormat Type:=0, Filename:=k & ".pdf"
158
-
159
- End If
160
196
 
161
197
  Next
162
198
 
@@ -166,4 +202,8 @@
166
202
 
167
203
 
168
204
 
205
+
206
+
207
+
208
+
169
209
  ```

1

追記

2021/06/09 01:14

投稿

jinoji
jinoji

スコア4592

test CHANGED
@@ -113,3 +113,57 @@
113
113
 
114
114
 
115
115
  ```
116
+
117
+ ---
118
+
119
+
120
+
121
+ <追記>別解を考えてみました。
122
+
123
+
124
+
125
+ ```VBA
126
+
127
+ Sub macro2()
128
+
129
+
130
+
131
+ Dim dic 'As Scripting.Dictionary
132
+
133
+ Set dic = CreateObject("Scripting.Dictionary")
134
+
135
+
136
+
137
+ Dim ws As Worksheet
138
+
139
+ For Each ws In Sheets
140
+
141
+ dic.Add ws.Name, ws
142
+
143
+ Next
144
+
145
+
146
+
147
+ Dim v, ary
148
+
149
+ For Each v In Array("100", "200", "300")
150
+
151
+ ary = Filter(dic.Keys, v)
152
+
153
+ If UBound(ary) > -1 Then
154
+
155
+ Worksheets(ary).Select
156
+
157
+ ActiveSheet.ExportAsFixedFormat Type:=0, Filename:=v & ".pdf"
158
+
159
+ End If
160
+
161
+ Next
162
+
163
+
164
+
165
+ End Sub
166
+
167
+
168
+
169
+ ```