我正在尝试将 Excel 工作表列表中单元格的字体颜色从红色更改为黑色。
该代码从 txt 文件中读取文件路径,然后将它们放入数组中。然后使用该数组检查 Excel 表的红色字体颜色并将其更改为黑色。
它不起作用,我对 VBscript 的了解有限。
REM Attribute VB_Name = "Module1"
Sub SimpleMacro()
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("pathlist.txt", ForReading)
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
arrServiceList = Split(strNextLine , ",")
Wscript.Echo "Server name: " & arrServiceList(0)
For i = 1 to Ubound(arrServiceList)
Wscript.Echo "Service: " & arrServiceList(i)
Next
Loop
Set objWorkbook = objExcel.Workbooks.Open(arrServiceList)
Set objWorksheet = objWorkbook.Worksheets(1)
RedColor = RGB(255, 0, 0)
BlackColor = RGB(0, 0, 0)
'Get number of rows in the specified column
RowsCount = Range("A1" *.End(xlDown)).Rows.Count
'Select cell
Range("A1" *.End(xlDown)).Select
'Loop the cells
For x = 1 To RowsCount
If ActiveCell.Font.Color = RedColor Then
'Change the text color
ActiveCell.Font.Color = BlackColor
Else
ActiveCell.Font.Color = BlackColor
End If
ActiveCell.Offset(1, 0).Select
Next
End Sub