Exit For End If Next dictKey GetColor = colorValueEnd Function还有一个过程,跟这个函数的使用关系不大,把对照表转换成代码字符串用的:Sub GenerateColorDictCode() Sheet1.Activate Dim colorDictCode As String Dim i As Integer For i = 1 To ActiveSheet.UsedRange.Rows.Count ...
在模块1里: FunctionGetColor(colorName As String)AsLongDimcolorDictAsObjectSetcolorDict=CreateObject("Scripting.Dictionary")colorDict("白")=rgb(255,255,255)colorDict("白色")=rgb(255,255,255)colorDict("White")=rgb(255,255,255)...此处略去100行colorDict("青绿")=rgb(127,255,212)colorDict("青绿...
Range("D" & i).Value = colorDictCode colorDictCode = "" Next End Sub 简单解释一下代码: 其实这个自定义函数很简单,ChatGPT开始给出的代码是这样的: Function GetColorByName(colorName As String) As Long Select Case colorName Case "Red" GetColorByName = RGB(255, 0, 0) Case "Green" GetColo...
Open Filename:="E:\code\exce_vba\1.xlsx" `打开Workbooks.Add `新建ActiveWorkbook.Sheet(1).Range("A1") = "wy" `操作ActiveWorkbook.Save `保存,一般在文档 ActiveWorkbook.SaveAs Filename:="E:\code\exce_vba\1.xlsx" `另存为 ActiveWorkbook.close `关闭`屏幕更新以及取消,成对出现 Application....
⧭VBA Code: The line of code will be: Range("D5").Interior.ColorIndex = Range("B5").Interior.ColorIndex ⧭Output: Run this code. It’ll change the background color of cellD5to match cellB5. Read More:How to Get the Cell Color in Excel (2 Methods) ...
官方文档:https://docs.microsoft.com/zh-cn/office/vba/api/overview/language-reference 代码完成后:工具-vbaproject属性-保护-查看时锁定-密码 编辑器 注释‘单引号开头,可通过调出编辑窗口批量注释和取消 强制转行:插入两个空格,下划线,回车 debug 在工具栏中,右键,调试工具栏 ...
Test the code: To test the function, apply Conditional Formatting to a cell, then enter a worksheet formula like: =ConditionalColor(A1,"interior") or =ConditionalColor(A1,"font") The first formula returns the color index number for the highlight color in cell A1, while the second returns ...
the current color of the pen as a string.PropertyGetPenColor()AsStringSelectCaseCurrentColorCaseRED PenColor ="Red"CaseGREEN PenColor ="Green"CaseBLUE PenColor ="Blue"EndSelectEndProperty' The following code gets the color of the pen' calling the Property Get procedure.ColorName = PenColor ...
只要按对象的层级一级一级往下找对象就可以: Sub ReadVBACode() Dim cm As CodeModule Set cm...CodeModule就是保存VBA代码的窗口,要读取CodeModule的代码,需要指定对应的起始行和终止行。...3、写入代码:能读取代码自然也可以写入代码,只需要换一换对象的方法即可: Sub WriteVBACode() Dim cm As Code...
Dim data_Code As String '代表参数代码 Dim iOpt As Variant '代表遍历配置选项的变量 Dim iOptStr As String '代表iOpt变量对应的配置值 rowS = UBound(arrExcel, 1) '遍历字典key得到参数编码 然后到Excel中去找对应的数据===Start1 For Each iKey In dic_Multi.KEYS ikey...