如果您想每次都添加时间,那么您必须在添加值之前将文件名“拆分”为名称和扩展名:
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