这是我的一个基本错误或缺乏理解。我在这里搜索了许多问题,似乎没有一个是适用的。
以下是代码
Option Explicit
Public Function ReturnedBackGroundColor(rnge As Range) As Integer
ReturnedBackGroundColor = rnge.Offset(0, 0).Interior.ColorIndex
End Function
Public Function SetBackGroundColorGreen()
ActiveCell.Offset(0, 0).Interior.ColorIndex = vbGreen
End Function
Public Function CountBackGroundColorGreen(rnge As Range) As Integer
Dim vCell As Range
CountBackGroundColorGreen = 0
For Each vCell In rnge.Cells
With vCell
If ReturnedBackGroundColor(vCell) = 14 Then
CountBackGroundColorGreen = CountBackGroundColorGreen + 1
End If
End With
Next
End Function
Public Function GetBackgroundColor() As Integer
Dim rnge As Range
GetBackgroundColor = 3
rnge = InputBox("Enter Cell to get Background color", "Get Cell Background Color")
GetBackgroundColor = ReturnedBackGroundColor(rnge)
End Function
我添加了最后一个函数,在此之前所有其他函数都正常工作,并且在该函数的第一个语句中得到错误。
对于该错误,可能的修复方法之一是在适当的库中添加引用。我不知道应该引用什么库,也找不到InputBox包含什么库。这是一个activeX控件,但我在tools->reference下拉菜单中看不到它。我确实检查了microsoft forms 2.0。
我尝试过各种set语句,但我认为我添加的唯一对象是inputbox。
有什么建议吗?
谢谢。
发布于 2018-06-09 06:50:00
使用application.inputbox,添加类型为range,设置返回的range对象。
Option Explicit
Sub main()
Debug.Print GetBackgroundColor()
End Sub
Public Function GetBackgroundColor() As Integer
Dim rnge As Range
Set rnge = Application.InputBox(prompt:="Enter Cell to get Background color", _
Title:="Get Cell Background Color", _
Type:=8)
GetBackgroundColor = ReturnedBackGroundColor(rnge)
End Function
Public Function ReturnedBackGroundColor(rnge As Range) As Integer
ReturnedBackGroundColor = rnge.Offset(0, 0).Interior.ColorIndex
End Function
https://stackoverflow.com/questions/50769193
复制相似问题