VBA - 使用 RefEdit 作为范围
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21881571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA - Using RefEdit as Range
提问by CJK
I have a VBA script which opens a UserForm so the user can select various cell addresses for copying information from one file to another. I am using RefEdit controls to designate the cell address, but I am receiving an object error when I try to use the Workbook.Range(UserForm.RefEdit.Value)
function, because the RefEdit reference is in the format "'Sheet1'!X#:X#". I know that if the RefEdit were just a range of cells I could do Workbook.Worksheet.Range(UserForm.RefEdit.Value)
, but the VBA script is being used for transitioning multiple files with different sheet names (so I can't use a universal Workbook.Worksheet
string). Is there any way to use the RefEdit reference with both sheet name and cell address as a range?
我有一个 VBA 脚本,它打开一个用户窗体,以便用户可以选择各种单元格地址,以便将信息从一个文件复制到另一个文件。我正在使用 RefEdit 控件来指定单元格地址,但是当我尝试使用该Workbook.Range(UserForm.RefEdit.Value)
函数时收到一个对象错误,因为 RefEdit 引用的格式为“'Sheet1'!X#:X#”。我知道如果 RefEdit 只是我可以做的一系列单元格Workbook.Worksheet.Range(UserForm.RefEdit.Value)
,但是 VBA 脚本用于转换具有不同工作表名称的多个文件(因此我不能使用通用Workbook.Worksheet
字符串)。有什么方法可以将 RefEdit 引用与工作表名称和单元格地址一起用作范围吗?
Here is my current code:
这是我当前的代码:
Sub ReviseFAA()
Dim FolderPath As String, FilePath As String
Dim SourceFAA As Workbook, RevisedFAA As Workbook
FolderPath = "A:\Copy of MWO File\"
FilePath = Dir(FolderPath & "*.xls")
Do While FilePath <> ""
Workbooks.Open (FolderPath & "FAA Template.xlsx")
Set RevisedFAA = Workbooks("FAA Template.xlsx")
Workbooks.Open (FolderPath & FilePath)
Set SourceFAA = Workbooks(FilePath)
FAA_User.Show
With SourceFAA
RevisedFAA.Sheets("Repair Instruction").Range("U2:AD3") = .Range(FAA_User.ControlNumber.Value).Value
End With
FilePath = Dir
Loop
回答by CRondao
I tried this and it worked:
我试过了,它奏效了:
Dim s, w
s = RefEdit1.Value
Set w = Range(s)
MsgBox w.Cells(1, 1)
回答by Pedrumj
Try using this:
尝试使用这个:
Range(UserForm.RefEdit.Value)
Remove the workbook
. and worksheet
.
删除workbook
. 和worksheet
。