简体   繁体   English

Excel VBA - 使用来自另一个工作簿的动态范围填充 ActiveX 组合框

[英]Excel VBA - Fill ActiveX Combobox with dynamic range from another workbook

I am trying to fill an ActiveX Combobox with a dynamic range from another workbook but I am getting a run-time error '1004' Application or object-defined error on the line of code that assigns the range:我正在尝试使用另一个工作簿中的动态范围填充 ActiveX 组合框,但在分配范围的代码行上出现运行时错误“1004”应用程序或对象定义错误:

Dim prfile1 As String
Dim prfile2 As String
Dim filepath As String
Dim checktotal As Integer
Dim checkrng As Range
Dim emunber As String

prfile1 = Worksheets("setup").Range("B10").Value
prfile2 = Worksheets("setup").Range("B7").Value
filepath = Worksheets("setup").Range("e10").Value
emunber = Worksheets("ReprintOld").Range("V3").Value

Workbooks.Open filepath & prfile2
Windows(prfile2).Activate

checktotal = Workbooks(prfile2).Worksheets(emunber).Range("AE1")
checkrng = Workbooks(prfile2).Worksheets(emunber).Range(Range("U5"), Range("U5").End(xlDown))

You need to qualify all your Range objects.您需要限定所有Range对象。

checktotal = Workbooks(prfile2).Worksheets(emunber).Range("AE1")

With Workbooks(prfile2).Worksheets(emunber)

    Set checkrng = .Range(.Range("U5"), .Range("U5").End(xlDown))

end with

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM