当我尝试通过宏
保存此文档时我收到错误运行时错误1004-您无法将此工作簿保存为同名。
我希望在运行宏时覆盖现有文档。
Sub sendemail()
'Save the form with todays date
Application.Save "doc.xlsm"
'Create the email
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "<HTML><BODY>"
strbody = strbody & "<A href= ""http://ne-sharepoint.xsxxu.xxcorp.xxx.biz/ASP/SFP/xP/xxx-OPS/Shared%20Documents/00.%20Shift%20Schedule/ShiftRota.xlsm"">Link to Sharepoint</A>"
strbody = strbody & "</BODY></HTML>"
On Error Resume Next
With OutMail
.To = "[email address]"
.cc = ""
.BCC = ""
.Subject = "New Holiday Request on " & Format(Now(), "dd/mm/yyyy") & " by " & Range("C2") & ""
.HTMLBody = strbody
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Debug.Print strbody
End Sub
答案 0 :(得分:1)
只需使用
Application.Save
如果你想保留文件名。
答案 1 :(得分:0)
'Save the form with todays date
Application.Save "doc.xlsm"
这表示您想将其保存在特定名称下?比如doc20131219.xlsm?如果那么
Application.Save "doc" & Format(Now(),"yyyymmddHhNnSs") & ".xlsm"