0

我的莲花代理有时会分离文件并将它们放入一个文件夹中,这些文件具有相同的名称,因此它们被覆盖了我想在将文件保存到文件夹之前重命名文件

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
                Call o.ExtractFile(fullpath) 
            End If
        End Forall
    End If
End If

你能告诉我我该怎么做吗?非常感谢 dsea

4

1 回答 1

4

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

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
于 2013-05-31T14:37:31.283 回答