2013-12-19 83 views
0

当我试图通过我的微距Excel的VBA不会保存

我得到的错误运行时错误本文档保存1004-您不能将此workbbook保存为相同的名称。

我希望在运行宏时覆盖现有的文档。

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 

回答

1

,如果你想保留的文件名只需使用

Application.Save 

0
'Save the form with todays date 
Application.Save "doc.xlsm" 

这表明你想要将它保存在一个特定的名称?如doc20131219.xlsm?如果是的话

Application.Save "doc" & Format(Now(),"yyyymmddHhNnSs") & ".xlsm"