从我之前的帖子(同名)开始跟进。我有一个用户表单,我需要根据下拉框“XXXXList”中的项目列表查找数据。 VBA代码部分工作。代码能够从内部网中查找并打开名为“database”的正确文件。但是一旦文件打开,我收到以下错误消息“自动化错误”。
我的代码是:
Private Sub ContractsList_AfterUpdate()
Dim WB As Workbook
Dim Sht As Worksheet
' set workbook to workbook location at internet
Set WB = Workbooks.Open("https://Private.Private.Private.uk/Private/Private/Private/Private/Private.xlsm")
Set Sht = WB.Worksheets("Availabledata")
Application.Wait (Now + TimeValue("00:00:01"))
Workbooks("database.xlsm").Close
With Me.XXXXList
'value to be found in Column H of 3rd worhseet
If Not IsError(Application.Match(.Value, Sht.Range("H:H"), 0)) Then
'Lookup values based on first control
Me.TextBox1 = Sht.Range("H" & Application.Match(.Value, Sheet3.Range("H9:H100"), 2)).Value '<-- value not found in Column H
Else
MsgBox "This contract is not on the list"
.Value = ""
Exit Sub
End If
End With
End Sub
此外,工作表“database.xlsm”意味着闪存一秒钟然后立即关闭,但它会询问我是否要保存数据。
我不想真的想要那个,是否可以跳过该步骤并自动关闭它?