如果您要添加的时间每次,那么你必须“分裂”的名和扩展名的文件名添加前值:
Dim strPath as String
Dim strExtension as String
Dim strFullPath as String
Set rtitem = curdoc.GetFirstItem("Body")
If Not rtitem Is Nothing Then
If Isarray(rtitem.EmbeddedObjects) Then
Forall o In rtitem.EmbeddedObjects
If (o.Type = EMBED_ATTACHMENT) Then
fullpath = path + o.source
If Instr(fullpath , ".") > 0 then
strPath = StrLeftBack(fullpath , ".")
strExtension = "." & StrRightBack(fullpath, ".")
Else
strPath = fullpath
strExtension = ""
End If
strFullPath = strPath & "-" & Format(Now , "yyyymmdd-hhnnss") & strExtension
Call o.ExtractFile(strFullPath)
End If
End Forall
End If
End If
当然你可以首先“检查”文件是否存在,并且只添加时间值(如果它不是唯一的):
Dim strExist as String
...
If (o.Type = EMBED_ATTACHMENT) Then
fullpath = path + o.source
strExist = Dir$(fullPath, 0)
If strExist <> "" then 'exists
If Instr(fullpath , ".") > 0 then
strPath = StrLeftBack(fullpath , ".")
strExtension = "." & StrRightBack(fullpath, ".")
Else
strPath = fullpath
strExtension = ""
End If
strFullPath = strPath & "-" & Format(Now , "yyyymmdd-hhnnss") & strExtension
Else
strFullPath = fullpath
End If
Call o.ExtractFile(strFullPath)
End If