質問編集履歴
4
具体的なこと記載
title
CHANGED
File without changes
|
body
CHANGED
@@ -115,6 +115,7 @@
|
|
115
115
|
### 試したこと
|
116
116
|
|
117
117
|
いろいろ調べてみたのですが改善されず困っております。
|
118
|
+
具体的には調べたのですが、エラー箇所から進めず困っています。
|
118
119
|
|
119
120
|
### 補足情報(FW/ツールのバージョンなど)
|
120
121
|
|
3
エラーの追記をしました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -102,10 +102,11 @@
|
|
102
102
|
|
103
103
|
|
104
104
|
```
|
105
|
-
エラー
|
105
|
+
コンパイルエラー ユーザー定義型は定義されていません。
|
106
106
|
```
|
107
107
|
|
108
108
|
### 該当のソースコード
|
109
|
+
R As Cells
|
109
110
|
|
110
111
|
```ここに言語名を入力
|
111
112
|
ソースコード
|
2
本文に記載してしまったコードを削除してCODEにうつしました
title
CHANGED
File without changes
|
body
CHANGED
@@ -100,144 +100,7 @@
|
|
100
100
|
|
101
101
|
エラーメッセージが発生してしまい、困っております。
|
102
102
|
|
103
|
-
わたしが書いたコードは
|
104
103
|
|
105
|
-
Option Explicit
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
Sub sendmail()
|
110
|
-
|
111
|
-
Dim ws As Worksheet
|
112
|
-
|
113
|
-
Set ws = ThisWorkbook.Sheets("mail")
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
Dim OutApp As Outlook.Application
|
118
|
-
|
119
|
-
Set OutApp = New Outlook.Application
|
120
|
-
|
121
|
-
Dim R As Long, lastrow As Long
|
122
|
-
|
123
|
-
lastrow = ws.Cells(2, 1).End(xlDown).Row
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
For R = 3 To lastrow
|
128
|
-
|
129
|
-
Dim OutMail As Outlook.MailItem
|
130
|
-
|
131
|
-
Set OutMail = OutApp.CreateItem(olMailItem)
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
Dim BodyOfMail As String
|
136
|
-
|
137
|
-
BodyOfMail = CreateBodyOfMail(ws, R)
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
'PDFファイル名生成
|
142
|
-
|
143
|
-
Dim R As Cells, ws As Object, dt As Variant
|
144
|
-
|
145
|
-
Set R = Cells(3, 7)
|
146
|
-
|
147
|
-
Set ws = CreateObject("WScript.shell")
|
148
|
-
|
149
|
-
dt = ws.SpecialFolders("Desktop") & "\" & "返信.pdf"
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
With OutMail
|
154
|
-
|
155
|
-
.SendUsingAccount = Session.Accounts(aaaaa@aaa.com)
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
.To = ws.Cells(R, 5).Value
|
160
|
-
|
161
|
-
.CC = ws.Cells(R, 6).Value & bbb@bbb.com & ccc@ccc.com & ddd@ddd.com
|
162
|
-
|
163
|
-
.subject = Replace(ws.Cells(2, 10).Value, "コード", ws.Cells(R, 3).Value, "都道府県", ws.Cells(R, 2).Value)
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
.body = BodyOfMail
|
168
|
-
|
169
|
-
.Attachments.Add dt & " .pdf"
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
End With
|
174
|
-
|
175
|
-
OutMail.Save
|
176
|
-
|
177
|
-
Set OutMail = Nothing
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
Next R
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
End Sub
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
Function CreateBodyOfMail(ws As Worksheet, R As Long) As String
|
198
|
-
|
199
|
-
Dim shimei As String, link As String
|
200
|
-
|
201
|
-
shimei = ws.Cells(R, 4).Value
|
202
|
-
|
203
|
-
shisetsu = ws.Cells(R, 2).Value
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
Dim subject As String
|
208
|
-
|
209
|
-
subject = ws.Cells(2, 2).Value
|
210
|
-
|
211
|
-
subject = Replace(subject, "都道府県", todou)
|
212
|
-
|
213
|
-
subject = Replace(subject, "コード", code)
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
Dim body As String
|
222
|
-
|
223
|
-
body = ws.Cells(3, 10).Value
|
224
|
-
|
225
|
-
body = Replace(body, "名前", shimei)
|
226
|
-
|
227
|
-
body = Replace(body, "都道府県", todou)
|
228
|
-
|
229
|
-
body = body & vbCrLf
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
CreateBodyOfMail = body
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
End Function
|
240
|
-
|
241
104
|
```
|
242
105
|
エラーメッセージ
|
243
106
|
```
|
1
codeに記載いたしました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,95 @@
|
|
1
|
+
```ここに言語を入力
|
1
|
-
|
2
|
+
Option Explicit
|
2
3
|
|
4
|
+
Sub sendmail()
|
5
|
+
|
6
|
+
Dim ws As Worksheet
|
7
|
+
|
8
|
+
Set ws = ThisWorkbook.Sheets("mail")
|
9
|
+
|
10
|
+
Dim OutApp As Outlook.Application
|
11
|
+
|
12
|
+
Set OutApp = New Outlook.Application
|
13
|
+
|
14
|
+
Dim R As Long, lastrow As Long
|
15
|
+
|
16
|
+
lastrow = ws.Cells(2, 1).End(xlDown).Row
|
17
|
+
|
18
|
+
For R = 3 To lastrow
|
19
|
+
|
20
|
+
Dim OutMail As Outlook.MailItem
|
21
|
+
|
22
|
+
Set OutMail = OutApp.CreateItem(olMailItem)
|
23
|
+
|
24
|
+
Dim BodyOfMail As String
|
25
|
+
|
26
|
+
BodyOfMail = CreateBodyOfMail(ws, R)
|
27
|
+
|
28
|
+
'PDFファイル名生成
|
29
|
+
|
30
|
+
Dim R As Cells, ws As Object, dt As Variant
|
31
|
+
|
32
|
+
Set R = Cells(3, 7)
|
33
|
+
|
34
|
+
Set ws = CreateObject("WScript.shell")
|
35
|
+
|
36
|
+
dt = ws.SpecialFolders("Desktop") & "\" & "返信.pdf"
|
37
|
+
|
38
|
+
With OutMail
|
39
|
+
|
40
|
+
.SendUsingAccount = Session.Accounts(aaaaa@aaa.com)
|
41
|
+
|
42
|
+
.To = ws.Cells(R, 5).Value
|
43
|
+
|
44
|
+
.CC = ws.Cells(R, 6).Value & bbb@bbb.com & ccc@ccc.com & ddd@ddd.com
|
45
|
+
|
46
|
+
.subject = Replace(ws.Cells(2, 10).Value, "コード", ws.Cells(R, 3).Value, "都道府県", ws.Cells(R, 2).Value)
|
47
|
+
|
48
|
+
.body = BodyOfMail
|
49
|
+
|
50
|
+
.Attachments.Add dt & " .pdf"
|
51
|
+
|
52
|
+
End With
|
53
|
+
|
54
|
+
OutMail.Save
|
55
|
+
|
56
|
+
Set OutMail = Nothing
|
57
|
+
|
58
|
+
Next R
|
59
|
+
|
60
|
+
End Sub
|
61
|
+
|
62
|
+
Function CreateBodyOfMail(ws As Worksheet, R As Long) As String
|
63
|
+
|
64
|
+
Dim shimei As String, link As String
|
65
|
+
|
66
|
+
shimei = ws.Cells(R, 4).Value
|
67
|
+
|
68
|
+
shisetsu = ws.Cells(R, 2).Value
|
69
|
+
|
70
|
+
Dim subject As String
|
71
|
+
|
72
|
+
subject = ws.Cells(2, 2).Value
|
73
|
+
|
74
|
+
subject = Replace(subject, "都道府県", todou)
|
75
|
+
|
76
|
+
subject = Replace(subject, "コード", code)
|
77
|
+
|
78
|
+
Dim body As String
|
79
|
+
|
80
|
+
body = ws.Cells(3, 10).Value
|
81
|
+
|
82
|
+
body = Replace(body, "名前", shimei)
|
83
|
+
|
84
|
+
body = Replace(body, "都道府県", todou)
|
85
|
+
|
86
|
+
body = body & vbCrLf
|
87
|
+
|
88
|
+
CreateBodyOfMail = body
|
89
|
+
|
90
|
+
End Function
|
91
|
+
```### 前提・実現したいこと
|
92
|
+
|
3
93
|
メール一斉作成PDF添付付きのコードを作成しています。
|
4
94
|
|
5
95
|
件名はエクセルの(2,10)にあり、件名中の(コード:都道府県)の箇所にエクセルのコード→(R,3)、都道府県→(R,2)を挿入したいと考えています。
|