从sharepoint

时间:2018-03-14 18:57:09

标签: excel-vba vba excel

我是VBA的新手,这个论坛对我很有帮助。我按照这个论坛上发布的帖子来查找我的问题的答案,我想感谢大家提供了很棒的解决方案。

我目前正致力于从SharePoint上发布的Excel文件生成汇总表。我已将sharepoint映射为网络驱动器。我试图一个接一个地从sharepoint文件夹打开所有文件,从不同的选项卡复制所需的数据,将其粘贴到摘要表并关闭文件。当我尝试运行代码时,它会给我一个运行时错误52作为“错误的文件名或数字”。

我在这里粘贴了部分代码。对此事的任何帮助都非常感激。

谢谢你, Pranav

Option Explicit
Sub GenerateSummary()

Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim Directory As String
Dim MyFile As String
Dim SummarySheet As Workbook

Set SummarySheet = Workbooks.Add

With Application.FileDialog(msoFileDialogFolderPicker)
    .Title = "Please select a folder"
    .Show
    .AllowMultiSelect = False

    If .SelectedItems.Count = 0 Then
        MsgBox ("You did not select a folder")
        Exit Sub
    End If

    Directory = .SelectedItems(1) & "\"
End With

MyFile = Dir(Directory & "*.xlsx")

Do While MyFile <> ""
    Workbooks.Open (Directory & MyFile)
    Sheets(Array(1, 2)).Select
    Sheets(1).Activate
    Sheets(Array(1, 2)).Copy Before:=SummarySheet.Sheets(1)
    ' Other statistics are calculated and operations are performed here

    MyFile = Dir()
    ActiveWindow.ActivateNext
    ActiveWorkbook.Close
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub

0 个答案:

没有答案