0

我正在尝试运行一个宏,该宏使用一组工作簿中的复选框更正链接的单元格指定。

一个文件中有许多(大约 100 个)工作簿需要调整。

因此,我正在遍历这些文件并运行重新分配,但是,它只适用于我编写宏的文件:

Sub CheckBoxesControl()

On Error Resume Next
    Dim path As String
    Dim file As String
    Dim wkbk As Workbook
    Dim i As Long


    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    path = "C:\file\path\"
    file = Dir(path)

    Do While Not file = ""
        Workbooks.Open (path & file)
        Set wkbk = ActiveWorkbook

    For i = 1 To 400
        ActiveWorkbook.Sheet4.CheckBoxes("Check Box " & i).LinkedCell = "ChkBoxOutput!AA" & i
        ActiveWorkbook.Sheet21.CheckBoxes("Check Box " & i).LinkedCell = "ChkBoxOutput!AB" & i
        Activekbook.Sheet22.CheckBoxes("Check Box " & i).LinkedCell = "ChkBoxOutput!AC" & i

    Next i

    wkbk.Save
    wkbk.Close
    file = Dir
    Loop

End Sub

谁能告诉我如何调整它以使其应用于每个文件?

宏运行没有错误(实际上文件中的每个文件似乎都被打开和关闭)。

4

1 回答 1

0

不要使用 ActiveWorkbook,它会混淆问题(与使用 ActiveCell / Selection 相同) - 这样做:

Do While Not file = ""
    Set wkbk = Workbooks.Open (path & file)

For i = 1 To 400
    wkbk.Sheet4.CheckBoxes("Check Box " & i).LinkedCell = "ChkBoxOutput!AA" & i
    wkbk .Sheet21.CheckBoxes("Check Box " & i).LinkedCell = "ChkBoxOutput!AB" & i
    wkbk .Sheet22.CheckBoxes("Check Box " & i).LinkedCell = "ChkBoxOutput!AC" & i

Next i

wkbk.Save
wkbk.Close
file = Dir
Loop
于 2013-06-12T09:22:41.613 回答