【问题标题】:Is it possible to upload sections of a Excel List to a SharePoint List with VBA?是否可以使用 VBA 将 Excel 列表的部分上传到 SharePoint 列表?
【发布时间】:2019-06-25 20:51:54
【问题描述】:

我正在设置一个新的 SharePoint 列表,我想将前四/五列上传到 SharePoint(它们的名称和内容匹配),然后是第 12 列,因为它包含 SharePoint 的第五列。在您询问之前,我没有权限或授权更改第 12 列的位置,因为该文档应该具有特定格式。

作为 VBA 新手,我不确定我是否了解如何连接到 SharePoint 网站,特别是此列表,然后上传 Excel 数据。我以前手动上传过excel数据,但我想自动化这个过程,所以我可以运行一个宏来上传工作表中的项目(现在我只希望他们在以后可以整理重复项后成功上传)我'我不要求有文档的代码草稿,我可以从更熟悉 Excel-VBA/SharePoint 交互的人那里获得一些帮助和指示。

我是 VBA 新手,所以我打开了包含我的数据的工作簿(但不是工作表)(我选择使用打开文件方法,因为我不会是唯一使用此宏的人,所以我决定允许人们导航到他们的目录。

Sub UploadUntimed()
    Dim my_FileName As Variant
    my_FileName = Application.GetOpenFilename(FileFilter:="Excel Files,*.xl*;*.xm*")
    If my_FileName <> False Then
        Workbooks.Open Filename:=my_FileName
    End If
End Sub

【问题讨论】:

    标签: excel vba sharepoint


    【解决方案1】:

    请试试这个。

    Private Sub CreateList()
        Dim folder As folder
        Dim f As File
        Dim fs As New FileSystemObject
        Dim RowCtr As Integer
        RowCtr = 1
        Set folder = fs.GetFolder("http://your_url_here/") '<=Variable Location
        For Each f In folder.Files
           Cells(RowCtr, 1).Value = f.Name
           RowCtr = RowCtr + 1
        Next f
    End Sub
    

    另外,试试这个。

    Sub UpdateSpecificCells()
    
    'If nobody has the file checked out
    If Workbooks.CanCheckOut("http://your_url_here/ExcelList.xlsb") = True Then
    Application.DisplayAlerts = False
    
    'Open the file on the SharePoint server
    Workbooks.Open Filename:="http://your_url_here/ExcelList.xlsb", UpdateLinks:=xlUpdateLinksNever
    
    
    ActiveSheet.Cells(2, 7).Value = 100
    ActiveSheet.Cells(3, 7).Value = 200
    ActiveSheet.Cells(4, 7).Value = 300
    
    
    'Close the workbook
    Workbooks("ExcelList.xlsb").Save
    Workbooks("ExcelList.xlsb").Close
    
    End If
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多