尝试从宏中打开多个工作表时关闭弹出窗口

25 浏览
0 Comments

尝试从宏中打开多个工作表时关闭弹出窗口

我正在尝试从多个工作表中提取一些数据,但是当我运行宏时,一些工作表会弹出窗口询问我是否更新或不更新连接到工作表的链接。我正在寻找一种方法使宏点击“不更新”。

顺便说一句,如果可能,我希望sFolder是根文件夹,并且还要在C:\\ temp中查找包含任何“*.xlsx”文件

Sub tgr()
    Dim wbDest As Workbook
    Dim wsDest As Worksheet
    Dim rCopy As Range
    Dim sFolder As String
    Dim sFile As String
    Dim lRow As Long
    Set wbDest = ThisWorkbook                   'The workbook where information will be copied into
    Set wsDest = wbDest.Worksheets("Sheet1")    'The worksheet where information will be copied into
    sFolder = "C:\Path\" 'The folder path containing the xlsx files to copy from
    'would like sFolder to be the root folder and also 
    '   search for any "*.xlsx" contained inside C:\temp
    lRow = 1 'The starting row where information will be copied into
    'Adjust the folder path to ensure it ends with \
    If Right(sFolder, 1) <> "\" Then sFolder = sFolder & "\"
    'Get the first .xlsx file in the folder path
    sFile = Dir(sFolder & "*.xlsx")
    'Begin loop through each file in the folder
    Do While Len(sFile) > 0
        'Open the current workbook in the folder
        With Workbooks.Open(sFolder & sFile)
            'Copy over the formulas from A1:C3 from only the first 
            '   worksheet into the destination worksheet
            Set rCopy = .Sheets(1).Range("C9:D26")
            wsDest.Cells(lRow, "A").Resize(rCopy.Rows.Count, rCopy.Columns.Count).Formula = rCopy.Formula
            'Advance the destination row by the number of rows being copied over
            lRow = lRow + rCopy.Rows.Count
            .Close False    'Close the workbook that was opened from the folder without saving changes
        End With
        sFile = Dir 'Advance to the next file
    Loop
End Sub

admin 更改状态以发布 2023年5月22日
0
0 Comments

更改

With Workbooks.Open(sFolder & sFile)

With Workbooks.Open(sFolder & sFile, UpdateLinks:=False)

有关此主题的更多信息,请查看:
如何消除更新链接警告?

0