vba - 复制和重命名文件
问题描述
我有一个访问数据库(后端)。大小正在急剧增加,我敢肯定是因为我的主表中有一个附件字段。
我决定存储文件路径名而不是文件本身;
我在这里找到了@Fionnuala,这个 VBA 例程和函数对我来说是完美的(我刚刚将 AllowMultiSelect 更改为 FALSE)。
如何将选定的文件复制到网络文件夹,然后使用字段 ID 作为名称的一部分对其进行重命名。喜欢 [ID] 和“lto.pdf”</p>
ID 是我的主表中的一个字段;
复制后的文件名将是O:/DOCS/678LTO.PDF
Private Sub Command7_Click()
Dim f As Object
Set f = Application.FileDialog(3)
f.AllowMultiSelect = FALSE
If f.Show Then
For i = 1 To f.SelectedItems.Count
sFile = Filename(f.SelectedItems(i), sPath)
MsgBox sPath & "---" & sFile
'Here I need to copy the file to O:\DOCS
'And rename it as [ID] & “lto.pdf” resulting O:\DOCS\328LTO.pdf
Next
End If
End Sub
Public Function Filename(ByVal strPath As String, sPath) As String
sPath = Left(strPath, InStrRev(strPath, "\"))
Filename = Mid(strPath, InStrRev(strPath, "\") + 1)
End Function
解决方案
使用文件复制方法
'Here I need to copy the file to O:\DOCS
'And rename it as [ID] & “lto.pdf” resulting O:\DOCS\328LTO.pdf
FileCopy f.SelectedItems(i), "O:\DOCS\" & Your[ID] & "LTO.pdf"
推荐阅读
- reactjs - 将商品添加到购物车 (addcartItems) 的 ReactContext 函数不起作用
- python-3.x - 为什么 Python 以十六进制打印转义序列?
- python - 一副纸牌的功能和输入
- php - 使用 GCP PHP 客户端库创建文件夹
- c# - Parallel.ForEach 和 AsParallel().ForAll(冻结)
- javascript - 当我创建一个新类时,尝试将数据推送到一个空数组没有按预期工作
- c - printf() 中的逗号分隔表达式给出了意外的结果
- prolog - 如何在不更改变量名的情况下加入序言中的两个列表
- karate - 空手道 - 在运行测试用例时编辑 xml
- swift - ScrollView 开始从右到左滚动 iOS