我正在尝试使用一个函数来更改辅助工作表范围内的背景颜色。代码是这样的:
Function pintar(fila As String, colI As String, _ colF As String, celdai As Integer, _ celdaf As Integer, xColor As String) As String Dim ci, cf, barra As String Dim micolor As Long Dim Re, Gr, Bl, fi As Integer micolor = CLng("&H" + xColor) Re = CInt(CLng("&h" + Left(xColor, 2))) Gr = CInt(CLng("&h" + Mid(xColor, 3, 2))) Bl = CInt(CLng("&h" + Right(xColor, 2))) 'Posiciones ci = colI & fila cf = colF & fila barra = ci & ":" & cf 'Range fi = CInt(fila) On Error GoTo ups Dim ws As Worksheet Dim rng As Range Set ws = Worksheets("cronograma") With ws Set rng = .Range(.Cells(fi, celdai), .Cells(fi, celdaf)) End With rng.Interior.color = RGB(Re,Gr,Bl) pintar = "OK" ups: MsgBox (CStr(Err.Number) + ": " + Err.Description) pintar = "Error" End Function
当我执行它时,在 rng.Interior.color = RGB(Re,Gr,Bl)行上收到运行时错误1004。 你能帮我这个忙吗?