0
Excelワークブックがあり、その中にいくつかのワークシートがあります。各ワークシートは個別に電子メールでお送りしたいドキュメントです。ランタイム1004エラーがCドライブに保存される
Office 2007を実行しているWindows XP SP3マシンにブックがあります.VBAコードは完全に動作し、個々のワークシートを電子メールで送信できます。
私は、Windows 7またはWindows 10 PC上でこれを実行する必要があり、私はエラーを取得する場合には、再びオフィス2007でこれは:
Sub EmailWithOutlook()
Dim oApp As Object
Dim oMail As Object
Dim WB As Workbook
Dim FileName As String
Dim wSht As Worksheet
Dim shtName As String
Application.ScreenUpdating = False
' Make a copy of the active worksheet
' and save it to a temporary file
ActiveSheet.Copy
Set WB = ActiveWorkbook
FileName = WB.Worksheets(1).Name
On Error Resume Next
Kill "C:\" & FileName
On Error GoTo 0
WB.SaveAs FileName:="C:\" & FileName
'Create and show the Outlook mail item
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
With oMail
'Uncomment the line below to hard code a recipient
'.To = "[email protected]"
'Uncomment the line below to hard code a subject
'.Subject = "Subject Line"
'Uncomment the lines below to hard code a body
'.body = "Dear John" & vbCrLf & vbCrLf & _
'"Here is the file you asked for"
.Attachments.Add WB.FullName
.Display
End With
'Delete the temporary file
WB.ChangeFileAccess Mode:=xlReadOnly
Kill WB.FullName
WB.Close SaveChanges:=False
'Restore screen updating and release Outlook
Application.ScreenUpdating = True
Set oMail = Nothing
Set oApp = Nothing
End Sub
含む行のルーチン停止以下: WB.SaveAs FileName:="C:\" & FileName
私は何が欠けていますか?
これは、ユーザーアカウント制御であるかもしれません。テストする代わりに、現在のブックのパスに保存してみてください。 – Rory