我有一个存储在Access表中的excel文件。我希望能够选择一个文件夹并将该文件解压缩到所选文件夹中,所有这些都在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
答案 0 :(得分:0)
您可以使用免费的Invantive Query Tool(我参与其中)将存储为OLE的文件导出到文件夹中,如下所示:
select olecolumn
from table
local export documents in <COLUMN-NAME> to "<DIRECTORY>" filename (automatic|column <COLUMN-NAME>) actions onerrorcontinue, extractole1
请注意,周围有各种OLE风味。这仅适用于OLE1格式。在一批中导出超过几GB的OLE文件时,请确保存在足够的物理内存。