-2
ワードファイルのパスを設定するVBAコードがあるので、電子メール本文としてドキュメントを使用できます。 代わりに、コードにセル参照を挿入して、コードを常に変更する必要はありませんでした。Excelのセルにドキュメントパスを設定する
ありがとうございます!以下は
私はあなたがrigth理解している場合はわからない
Sub Email()
Dim oOutApp As Object
Dim oMailItem As Object
Dim oWordApp As Object
Dim oWordDoc As Object
Dim oMailWordDoc As Object
Dim sh As Worksheet
Dim cell As Range
Dim FileCell As Range
Dim rng As Range
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set sh = Sheets("details")
On Error GoTo CleanUp
Set oWordApp = CreateObject("Word.Application")
Set oWordDoc = oWordApp.documents.Open("...File path..")
oWordDoc.Content.copy
Set oOutApp = CreateObject("Outlook.Application")
For Each cell In sh.Columns.Range("B3:B10000").cells.SpecialCells(xlCellTypeConstants)
Set rng = sh.cells(cell.Row, 1).Range("I1:J1")
If cell.Value Like "*" And _
Application.WorksheetFunction.CountA(rng) > 0 Then
Set oMailItem = oOutApp.CreateItem(0)
With oMailItem
.To = cell.Value
.cc = cells(cell.Row, "C").Value 'sh.Columns.Range("C3").cells
.Subject = cells(cell.Row, "F").Value
.Body = ""
For Each FileCell In rng.SpecialCells(xlCellTypeConstants)
If Trim(FileCell) <> "" Then
If Dir(FileCell.Value) <> "" Then
.Attachments.Add FileCell.Value
End If
End If
.Display
Next FileCell
Set oMailWordDoc = oOutApp.ActiveInspector.WordEditor
Set editor = .GetInspector.WordEditor
editor.Content.Paste
.send
End With
End If
Next cell
Set oMailWordDoc = oOutApp.ActiveInspector.WordEditor
CleanUp:
oWordApp.Quit
Set oMailWordDoc = Nothing
Set oMailItem = Nothing
Set oOutApp = Nothing
Set oWordDoc = Nothing
Set oWordApp = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
修正コードを提案できるように、現在のコードを投稿してください。 – Sixthsense
コードに@sixthsenseを指定しました – JSJ
コードにパスが表示されません。 – Sixthsense