【发布时间】:2017-06-08 09:55:51
【问题描述】:
我有一些代码用于打开 xlsm 工作簿,从中复制一些数据并将其与代码一起粘贴到工作簿中。两个工作簿都受密码保护,代码受密码保护。我有一些代码设置为在保存、打开和关闭之前运行,这些代码会锁定工作簿。
所以问题是在工作簿被 vba 打开后代码停止并且没有错误,如下所示。我认为这与 shift 键有关,这是我在网上看到的 open 方法的问题,但我更改了代码来解决这个问题,问题仍然存在。然后我尝试删除正在打开的工作簿中打开的代码并且它有效。为什么是这样?我之前使用打开代码的工作簿运行过这样的代码,并且运行良好。
我正在使用 Excel 2013。
Sub User_Update()
Application.ScreenUpdating = False
Dim strCurrentProgram As String
Dim MainProgramName As String
Dim strLocation As String
strLocation = "X:\Produktionsmesstechnik\Gehaeuse_Freigabe\"
strCurrentProgram = Dir(strLocation & "*.xlsm")
Do While strCurrentProgram <> ""
If InStr(strCurrentProgram, "Gehäuse Freigabe Program Ver") = 1 Then
If MainProgramName = "" Then
MainProgramName = strCurrentProgram
ElseIf CInt(Mid(MainProgramName, 29, 3)) < CInt(Mid(strCurrentProgram, 29, 3)) Then
MainProgramName = strCurrentProgram
End If
End If
strCurrentProgram = Dir
Loop
Workbooks.Open Filename:=strLocation & MainProgramName <<<< CODE STOPS HERE
ActiveWorkbook.Sheets("Users").Range(Cells(4, 1), Cells(100, 11)).Copy
Call UserPassword_Unlock
ThisWorkbook.Sheets("Users").Range("A4").Paste
ThisWorkbook.Save
Workbooks(MainProgramName).Close
Call UserPassword_Lock
结束子
【问题讨论】:
-
您可能遇到了这个错误:jkp-ads.com/articles/workbookopenbug.asp