【问题标题】:Export an Excel file stored in an Access table in a OLE field to a folder将存储在 OLE 字段中的 Access 表中的 Excel 文件导出到文件夹
【发布时间】: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/…
  • 谢谢你,我会看一下代码......我希望有一个更简单的方法......我很惊讶这样的事情并不容易做到,即在几行代码...
  • 我仍然有问题...任何人都可以提供一些工作示例代码?

标签: excel vba ole


【解决方案1】:

您可以使用免费的 Invantive 查询工具(我参与其中)将存储为 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文件时,请确保有足够的物理内存。

【讨论】:

  • 所提供的答案绝对是胡言乱语。
  • 我怎样才能帮助你使它不乱码?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-18
相关资源
最近更新 更多