我想要一个引用外部工作簿的函数。我写了这段代码,但收到“运行时错误'9”。
$('.rating').each(function(){
var _parent=$(this);
var originalStars = _parent.html();
$(_parent).on('mouseover','i[class*=" fa-star"]',function(){
$(this).prevAll().andSelf().removeClass('fa-star-o').addClass('fa-star');
}).mouseout(function(){
$(_parent).html(originalStars)
})
})
答案 0 :(得分:1)
您没有打开外部工作簿。如果要引用已关闭的外部工作簿,仍需要打开并阅读该信息。打开后,您还需要关闭外部工作簿。由于您只是想确定单个列中是否存在单元格,因此工作表的MATCH function更适合。
Function SiteStatus(Arg1 As String) As String
With Workbooks.Open(Filename:="D:\RFS.xlsx", ReadOnly:=True)
With .Worksheets(3)
With .Range(.Cells(2, 2), .Cells(Rows.Count, 2).End(xlUp))
If IsError(Application.Match(Arg1, .Cells, 0)) Then
SiteStatus = "ÑæÔä"
Else
SiteStatus = "ÎÇãæÔ"
End If
End With
End With
.Close SaveChanges:=False
End With
End Function
.Worksheets(3)
引用很危险。只需要有人将工作表重新排序到他们的首选队列顺序就可以打破这个功能。
为什么需要UDF?如果您指定工作表VLOOKUP function,则.Name property可以调用已关闭的外部工作簿。