密码失败后,从MS Access VBA关闭加密的excel

您所在的位置:网站首页 access不能导入excel 密码失败后,从MS Access VBA关闭加密的excel

密码失败后,从MS Access VBA关闭加密的excel

2023-04-08 11:57| 来源: 网络整理| 查看: 265

我在加密的excel文件中保留API的ID (向其他建议开放),并使用Microsoft打开加密的excel并提取ID。

问题是,如果密码不正确,它将无法关闭excel。如果输入密码正确,此代码工作正常。

Public Function getDeploymentID() As String Dim fileLocation As String fileLocation = "___DeploymentID.xlsx" Dim objExcel As Object Set objExcel = CreateObject("Excel.Application") Dim wb As Excel.Workbook On Error GoTo getDeploymentID_ERROR MsgBox "The development password is in a password protected excel. It will prompt you for the password next" Set wb = Workbooks.Open(fileLocation, True) 'User must enter password to continue. If they don't it'll error out on above line DoEvents 'Get deploymentID getDeploymentID = wb.Worksheets("Sheet1").Cells(1, 1) 'Close it 'wb.Close 'will close workbook, won't close excel wb.Application.Quit 'will close workbook and excel DoEvents GoTo getDeploymentID_Cleanup getDeploymentID_ERROR: Debug.Print "Failed to open DeploymentID excel file. Error " & err.Number & ":" & err.description objExcel.Quit 'THIS IS NOT WORKING DoEvents getDeploymentID_Cleanup: Set wb = Nothing Set objExcel = Nothing End Function


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3