vb问题,请问读取excel的sheet1的单元格cells(1,1)的值是RGB(255, 0, 0)的问题
excel的sheet1的单元格cells(1,1)的值是RGB(255,0,0),但在vb代码中,读取cells(1,1)后,将这值个赋给picture1.BackCo...
excel的sheet1的单元格cells(1,1)的值是RGB(255, 0, 0),但在vb代码中,读取cells(1,1)后,将这值个赋给picture1.BackColor总是“类型不匹配”,发现cells(1,1)的值在vb中是带引号出现的,即"RGB(255, 0, 0)",所以请问这个引号怎样去除掉从而可以赋值给picture1.BackColor呢?
展开
1个回答
展开全部
"RGB(255, 0, 0)" 是一个字符串,RGB(255, 0, 0) 是一个函数调用返回值是长整型
可以写个函数来处理这个字符串
picture1.BackColor=fun_DealColorString(cell的值)
Function fun_DealColorString(ByVal sColorstring As String) As Long
Dim sV As String
Dim vA As Variant
If Not (Left(sColorstring, 4) = "RGB(" And Right(sColorstring, 1) = ")") Then fun_DealColorString = 0
sV = Mid(sColorstring, 5) '去掉RGB(
sV = Left(sV, Len(sV) - 1) '去掉尾部的)
vA = Split(sV, ",") '把三个数取出来
fun_DealColorString = RGB(CInt(vA(0)), CInt(vA(1)), CInt(vA(2)))
End Function
可以写个函数来处理这个字符串
picture1.BackColor=fun_DealColorString(cell的值)
Function fun_DealColorString(ByVal sColorstring As String) As Long
Dim sV As String
Dim vA As Variant
If Not (Left(sColorstring, 4) = "RGB(" And Right(sColorstring, 1) = ")") Then fun_DealColorString = 0
sV = Mid(sColorstring, 5) '去掉RGB(
sV = Left(sV, Len(sV) - 1) '去掉尾部的)
vA = Split(sV, ",") '把三个数取出来
fun_DealColorString = RGB(CInt(vA(0)), CInt(vA(1)), CInt(vA(2)))
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询