访问VBA自动化功能,可以将Word文档保存到Sharepoint,但不能保存到Excel电子表格

时间:2018-11-07 05:34:32

标签: excel vba ms-access sharepoint ms-word

我有一个Access数据库,该数据库创建文件并将其保存到内部网络上的Sharepoint。在两种情况下,文件是Word文档,将它们保存到Sharepoint效果很好。其中两个文件是Excel电子表格,并且无法使用save或savecopy保存它们。最后一个文件是PowerPoint,保存它也失败。

有效的Word保存如下:

Set objWord = New Word.Application
Set objDoc = objWord.Documents.Add
objWord.Visible = True
Set objSelection = objWord.Selection
Set objRange = objDoc.Range

Creation of document

Dim SPAddress As String
SPAddress = GetSPAddress(iProjectId) & "ProjectFactSheet_" & sSiteName & "_" & Format(Now(), "yyyymmddhhnnss") & ".docx"
objDoc.SaveAs SPAddress

失败的Excel保存如下:

Set oExcelApp = CreateObject("Excel.Application")
oExcelApp.Visible = True
oExcelApp.AskToUpdateLinks = False
oExcelApp.DisplayAlerts = False
oExcelApp.Workbooks.Open ("c:\apps\" & strReportName)
SPAddress = GetSPAddress()
oExcelApp.ActiveWorkbook.SaveAs SPAddress & strReportName
  • savecopyas也出现错误。

此操作失败,错误文件名无法访问。该文件可能已损坏,位于未响应或只读的服务器上。

Public Function GetSPAddress(Optional lngQuaID As Long) As String
    GetSPAddress = ""

    If IsNull(lngQuaID) Or lngQuaID = 0 Then
        GetSPAddress = DLookup("SPBasePath", "AppData")
    Else
        If IsNull(DLookup("[SPPath]", "QualificationLog", "[QuaID] = " & lngQuaID)) Then
            GetSPAddress = DLookup("SPBasePath", "AppData")
        Else
            GetSPAddress = DLookup("[SPPath]", "QualificationLog", "[QuaID] = " & lngQuaID)
        End If
    End If
End Function

1 个答案:

答案 0 :(得分:0)

我唯一想到的建议是打开报表时设置一个工作簿变量,这样就可以绝对确定要保存哪个文件(尽管它本身不会引起错误...)< / p>

Dim wb As Object   '<<<
Set oExcelApp = CreateObject("Excel.Application")
oExcelApp.Visible = True
oExcelApp.AskToUpdateLinks = False
oExcelApp.DisplayAlerts = False
Set wb = oExcelApp.Workbooks.Open("c:\apps\" & strReportName) '<<<
SPAddress = GetSPAddress()
wb.SaveAs SPAddress & strReportName '<<<