For Each rs In Sheets If rs.Range("F3").Value <> "" Then rs.Name = rs.Range("F3") End If Next rs
End Sub
Excel中通过VBA批量修改特定位置颜色
单个无条件修改全部工作表
1 2 3 4 5 6 7 8 9 10 11
Sub BackGroudColor()
Dim rs2 As Worksheet
For Each rs2 In Sheets rs2.Range("C6").Interior.Color = RGB(180, 198, 231) rs2.Range("B7").Interior.Color = RGB(255, 230, 153) rs2.Range("E6").Interior.Color = RGB(198, 224, 180) Next rs2
End Sub
有条件修改目前工作表
1 2 3 4 5 6 7 8 9 10
Sub Fill_Cell_Condition()
Dim rngCell As Range For Each rngCell In Range("A6:A19") If Len(rngCell.Value) <> "0" Then rngCell.Cells.Interior.Color = RGB(255, 230, 153) 'If Everything in A6-A19 The length of the cell value is not zero, change backgroud color. Otherwise, do nothing End If Next rngCell
修改全部工作表的代码为 Dim ws As Worksheet For Each ws In Sheets ###在中间插入你想要全部工作表都修改的代码 Next ws ======================================== Sub Fill_Cell_Condition()
Dim wsFill As Worksheet Dim i
For Each wsFill In Sheets For i = 8 To 20 If wsFill.Cells(i, 1).Value <> "" Then '当A8-A20里不是没有值,则着色 wsFill.Cells(i, 1).Interior.Color = RGB(155, 30, 153) End If Next
Step 1: Hold down the ALT + F11 keys in Excel, and it opens the Microsoft Visual Basic for Applications window
Step 2: Click Insert > Module, and paste the following code in the Module Window
Step 3: 复制以下代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Sub Splitbook() 'Updateby20140612 Dim xPath As String xPath = Application.ActiveWorkbook.Path Application.ScreenUpdating = False Application.DisplayAlerts = False For Each xWs In ThisWorkbook.Sheets xWs.Copy Application.ActiveWorkbook.SaveAs Filename:=xPath & "\" & xWs.Name & ".xlsx" Application.ActiveWorkbook.Close False Next Application.DisplayAlerts = True Application.ScreenUpdating = True End Sub
# Press Shift+F10 to execute it or replace it with your code. # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings. defcreate_wb_from_ws(): try: filepath = 'D:\sp\test.xlsx'
from win32com.client import DispatchEx excel = DispatchEx("Excel.Application")
if excel == None: print('-' * 100) print('Error: Excel is not found on this machine. Existing!') print('-' * 100) return else: print('-' * 100) print('Message: Excel version {0} is available.'.format(excel.version)) print('-' * 100)