Ich habe eine Excel-Arbeitsmappe, mit mehreren Arbeitsblättern darin. Jedes Arbeitsblatt ist ein Dokument, das ich separat per E-Mail versenden möchte.Runtime 1004 Fehler beim Speichern auf C-Laufwerk
Ich habe die Arbeitsmappe auf einem Windows XP SP3-Computer ausgeführt Office 2007. Der VBA-Code funktioniert einwandfrei, und ich kann jedes einzelne Arbeitsblatt per E-Mail senden.
Ich brauche dies auf einem Windows 7 oder Windows 10 PC laufen, wieder mit Office 2007. Dies ist, wo ich den Fehler:
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
Die Routine Stationen auf der Linie enthält, die folgenden: WB.SaveAs FileName:="C:\" & FileName
Was vermisse ich?
Es könnte Kontensteuerung sein Benutzer zu schreiben hat . Versuchen Sie stattdessen, den Pfad der aktuellen Arbeitsmappe zu speichern, um sie zu testen. – Rory