【发布时间】:2014-06-17 14:43:52
【问题描述】:
我有一个 Excel 文件存储在 Access 表中。我希望能够选择一个文件夹并将该文件提取到所选文件夹中,所有这些都在 VBA 中。我完成了文件夹选择部分,并且通过 RecordSet 选择表中的字段也完成了。我没有的是如何将文件保存到选定的路径。
sub ExportEmbededFiles()
Dim strFolderPath As String
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
Dim oleObj As OLEObject
strFolderPath = SelectFolder("Select Folder to Export File to...")
'strFolderPath = "C:\Temp\" 'used for testing
Debug.Print strFolderPath
Set oleObj = New OLEObject
Set dbs = CurrentDb
Set rs = dbs.OpenRecordset("Select * FROM [Excel Template]")
If rs.BOF And rs.EOF Then
Debug.Print "no records in table"
rstTemp.Close
dbs.Close
Set rs = Nothing
Set dbs = Nothing
Exit Sub
Else
With rs
.MoveFirst 'rs
Do While Not .EOF 'rs
'this is where im stuck....
Set oleObj = rs!File
'save the embeded file to the path given above in
'oleObj.Save (strFolderPath)
.MoveNext ' rs
Loop
End With
End If
rs.Close
dbs.Close
Set rs = Nothing
Set dbs = Nothing
End Sub
【问题讨论】:
-
查看 DAO 方法 GetChunk。您编写一个循环以从该字段中读取某个块大小,然后您可以将其附加到文件中,并继续这样做,直到达到总文件大小。这是一些文档:google.co.nz/… 和一个示例:bytes.com/topic/access/answers/…
-
谢谢你,我会看一下代码......我希望有一个更简单的方法......我很惊讶这样的事情并不容易做到,即在几行代码...
-
我仍然有问题...任何人都可以提供一些工作示例代码?