gpt4 book ai didi

excel - 在 protected 工作表上运行宏

转载 作者:行者123 更新时间:2023-12-04 22:16:31 26 4
gpt4 key购买 nike

我正在尝试在 VBA 中运行一个宏,它列出了特定文件夹的所有文件及其超链接。我的代码在不 protected 时有效。但是当它受到保护时它不起作用。这是我的超链接宏。当工作表受到保护时,我所有的其他宏都可以工作。只是不是超链接之一。我已将私有(private)子宏存储在 中本工作手册

Sub updatting()

Dim xFSO As Object
Dim xFolder As Object
Dim xFile As Object
Dim xPath As String
Dim I As Integer
xPath = "C:\Users\risha\Downloads\a_few_little_tests\New folder"
If xPath = "" Then Exit Sub
Set xFSO = CreateObject("Scripting.FileSystemObject")
Set xFolder = xFSO.GetFolder(xPath)
For Each xFile In xFolder.Files
I = I + 1
ActiveSheet.Hyperlinks.Add Cells(I, 14), xFile.Path, , , xFile.Name
Next

End Sub

Private Sub Workbook_Open()


Sheet3.Protect Password:="abc", UserInterFaceOnly:=True



End Sub

最佳答案

在 I = I + 1 之后检查这个

   I = I + 1
ActiveSheet.Cells(I, 14).Value = xFile.Name
ActiveSheet.Hyperlinks.Add Cells(I, 14), xFile.Path, , , xFile.Name

关于excel - 在 protected 工作表上运行宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68604758/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com