更新链接提示问题。

15 浏览
0 Comments

更新链接提示问题。

我有一个长度代码,它打开了一组文件,取消了隐藏并导航到特定的工作表,复制一个范围并将该范围粘贴到另一个工作簿中。

问题在于,每当代码打开这些文件时,会出现一个弹出消息以更新链接。我知道可以通过updatelinks = 0解决这个问题,但想知道我应该在代码中包含哪里。

此外,代码执行需要时间,因此是否有任何修改可加快执行速度。

Sub mergeallinputworkbooks()  
    Dim wkbDest As Workbook
    Dim wksDest As Worksheet
    Dim wkbSource As Workbook
    Dim wksSource As Worksheet
    Dim MyPath As String
    Dim MyFile As String
    Dim FolderName As String
    Dim oCell As Range          
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Application.EnableEvents = False 
    Set wkbDest = ThisWorkbook
    Set wksDest = wkbDest.Worksheets("Master Data") 
    With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False
        .Show
        On Error Resume Next
        FolderName = .SelectedItems(1)
        Err.Clear
        On Error GoTo 0
    End With 
    MyPath = FolderName 
    If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\" 
    MyFile = Dir(MyPath & "*.xls")
    Do While Len(MyFile) > 0
        Set wkbSource = Workbooks.Open(MyPath & MyFile)
        Set wksSource = wkbSource.Worksheets("Scoring DB")
        ActiveWorkbook.Unprotect ("pyroo123")
        Sheets("Scoring DB").Visible = True
        Sheets("Scoring DB").Select
        Range("A4:W4").Copy
        Windows("Performance Dashboard.xlsm").Activate
        With Sheets("Master Data").Range("$A:$A")
        With Sheets("Master Data")
Set oCell = .Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0)
End With
oCell.Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False
        Windows("Performance Dashboard.xlsm").Activate
    End With  
        wkbSource.Close savechanges:=False
        MyFile = Dir
    Loop
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    Application.EnableEvents = True  
End Sub

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

针对你的链接问题,查看这个帖子。那里提供了足够的信息,可以很好地指示你如何和在哪里使用链接更新。

现在的代码建议
为了提高代码的性能,建议不要在不必要的情况下与工作表进行交互。而是将范围赋值给数组,而不是“复制并粘贴”:

arrMyRange = Worksheets("SourceWorksheet").Range("A4:W4")

这将创建你的数组。现在将数组分配到你的位置:

Worksheets("DestinationWorksheet").Range("A1").Resize(UBound(arrMyRange, 1), UBound(arrMyRange, 2)).Value = arrMyRange 

A1 可根据需要进行动态更改。

0