|
楼主 |
发表于 2022-4-9 15:26
|
显示全部楼层
前期工作代码,提示哪些工作簿需密码才能打开。
Sub ggg()
Dim p As String, oldn As String, r As Integer, i As Byte, wbn As String, wb As Workbook
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = -1 Then
p = .SelectedItems(1) & IIf(Right(.SelectedItems(1), 1) = "\", "", "\")
Else
Exit Sub
End If
End With
Worksheets.Add
Cells(1) = "下列文件需凭密码打开:"
oldn = ActiveWorkbook.Name
wbn = Dir(p & "*.xlsx")
Do
If wbn = "" Then Exit Sub
r = ActiveSheet.UsedRange.Rows.Count + 1
On Error Resume Next
Set wb = Workbooks.Open(Filename:=p & wbn, Password:="")
If wb.HasPassword Then
Workbooks(oldn).Worksheets(1).Hyperlinks.Add Cells(r, 1), p & wbn, , wbn, wbn
Cells(r + 1, 1).Select
End If
wb.Close False
wbn = Dir
Loop
Set wb = Nothing
End Sub
上述代码无法在执行完毕后用对话框msgbox提示一下,选择单元格的语句放在最后也无法执行,不知这是一种什么情况? |
|