Sharepoint上的Excel前端和Access后端

时间:2016-01-11 14:59:54

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

我有一个在Excel 2010中构建的VBA应用程序,并使用Access 2010作为后端来存储所有数据。我需要升级到SharePoint以便用户访问它,但我开始怀疑我是否会遇到此问题。如果我将两个文件都放在文档库中会有效吗?或者我会遇到问题?鉴于我的Excel前端已经完全开发,此时我无法对其进行更改,除了将所有数据存储在Excel中之外,还有其他选项可以使其工作吗?

2 个答案:

答案 0 :(得分:0)

我不完全确定您要实现的目标,但您只需将Excel和Access文件存储在文档库中即可。每个用户都必须下载这两个文件并在其本地计算机上执行VBA代码。我不知道有哪些机制可以帮助您链接Access和执行VBA代码,还可以在SharePoint Web库/视图/界面中显示基于此VBA代码的一些Excel数据。 SharePoint只是没有可以理解或执行VBA宏的组件。文档库可用于存储文档的文档和元数据。如果您尝试从excel Web查看器中打开excel,则可能会因为您的Excel已启用宏并且查看器不支持它而引发错误。

一旦我必须创建excel报告并直接在excel web查看器中显示它,我必须编写一个C#程序,它将生成包含已处理数据的普通xlsx文件,然后将其作为普通xlsx上传,以便excel web viewer可以打开它。

答案 1 :(得分:0)

我发现最好的方法是让用户从SharePoint打开它(痛苦)或者只是将文件保存在他们的计算机上。然后,当Excel开始将驱动器映射到SharePoint站点时,将Access数据库文件从映射驱动器传输到临时文件夹,然后删除映射的驱动器。然后,当进行更改时,只需重复相同的过程,但将Access文件复制到映射的驱动器。

我应该提一下,在我的环境中,用户很少更新这些信息,所以这样可以正常工作,但是如果用户经常更新数据,这不是最好的路线。

Sub GetSharePointFile()
    Dim objNet as object
    Dim strDriveLetter as String
    Dim strSharePointDatabaseFolder as String
    Set objNet = CreateObject("WScript.Network")

    On Error GoTo AUTH_Connection:
    strDriveLetter = GetOpenDriveLetter
    strSharePointDatabaseFolder = "<SharePoint site>"
    objNet.MapNetworkDrive strDriveLetter, strSharePointDatabaseFolder

On Error GoTo ErrHandler:
    <code to copy file(s) from mapped drive to destination folder> 

    Exit Sub

AUTH_Connection:

    Dim xlApp As New Excel.Application
    Dim xlDoc As Workbook
    On Error GoTo ErrHandler:

    Set xlApp = CreateObject("Excel.Application")
    Set xlDoc = xlApp.Workbooks.Add
    ' Trying to upload the file below will force IE to open and prompt user for their Username and Password which will authenticate them
    xlDoc.SaveAs FileName:="<SharePointSite>", FileFormat:=xlWorkbookNormal, AddToMru:=False
    xlDoc.Close
    xlApp.Quit

    objNet.MapNetworkDrive strDriveLetter, strSharePointDatabaseFolder
    Resume Next
ErrHandler:
    MsgBox Err.Code, Err.Description
End Sub

Function GetOpenDriveLetter() As String
Dim colDisks As Variant
Dim objWMIService As Object
Dim objDisk As Variant

  'Get all used Drive-Letters
  Set objWMIService = GetObject("winmgmts:\\" & "." & "\root\cimv2")
  Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")

  'Loop through all Drive-Letters
  For Each objDisk In colDisks
      For i = 67 To 90
          'If letter is in use store chr number as 'j' and exit loop
          If i = Asc(objDisk.deviceID) Then
              j = i
              Exit For
          'If not in use and the character value of i is not blank, then set and exit
          ElseIf i > j And Chr(i) <> "" Then
              GetOpenDriveLetter = Chr(i) & ":"
              Exit Function
          End If
      Next i
  Next objDisk
End Function