0

我在 Access 2007 数据库中有一个函数,在我的 PC 升级到 Office 2010 之前它一直运行良好。程序如下,违规行是设置了“originalFolder”的位置:

Function ExportToSharePoint()
Dim oFs As New FileSystemObject
Dim originalFolder As Folder
Dim destinationPath As String
Dim ofile As file
Dim XLApp As Excel.Application
Dim xlwb As Excel.Workbook
Dim strFileName As String
Dim oFolder As String
oFolder = "//chs114file1/dovpasres/Public/Script/InfoCentre/Delays"
Set oFs = CreateObject("Scripting.FileSystemObject")
Set XLApp = New Excel.Application
    Kill "K:\Public\Script\InfoCentre\Delays\*.xlk"
    Set originalFolder = oFs.GetFolder(oFolder)  
    destinationPath = "https://companyname.sharepoint.com/PRR/Documents/"

    For Each ofile In originalFolder.Files

        strFileName = oFs.GetFileName(ofile)

            Set xlwb = XLApp.Workbooks.Open(ofile)
            xlwb.SaveAs (destinationPath + strFileName)

    Next

xlwb.Close True
XLApp.Quit
Set xlwb = Nothing
Set XLApp = Nothing

End Function

我得到的错误是:

错误 13:数据类型不匹配

我很困惑,因为这是一个字符串,按要求?

4

1 回答 1

0

Microsoft 文档将GetFolder返回类型列为Folderis ,但我怀疑您的问题是由后期绑定(通过CreateObject)与早期绑定(通过强类型的文件夹变量)混合引起的。
要么导入引用以避免CreateObject调用,要么将类型更改为变体,或者可能是对象:

Dim originalFolder As variant
于 2013-03-27T15:44:28.990 回答