是否可以创建将执行以下操作的批处理文件?
由于
答案 0 :(得分:1)
创建两个文件:批处理文件和批处理文件调用的VBScript文件。在VBS中操作Excel的工作很容易。
<强> modder.bat 强>
:Start
@Echo off
CScript modder.vbs
:End
<强> modder.vbs 强>
'launch Excel and open file
Set xlObj = CreateObject("Excel.Application")
Set xlFile = xlObj.WorkBooks.Open("c:\temp\filename.xls")
'turn off screen alerts
xlObj.Application.DisplayAlerts = False
'loop through sheets
For Each Worksheet In xlFile.Worksheets
'change sheet to desired worksheet name
If Worksheet.Name = "SheetToRename" Then
Worksheet.Name = "NewName"
End If
'change all sheets to desired font
With Worksheet.Cells.Font
.Name = "Verdana"
.Size = 12
End With
Next
'save, close, then quit
xlFile.Close True
xlObj.Quit
modder.vbs (根据要求使用workday()函数)
'launch Excel and open file
Set xlObj = CreateObject("Excel.Application")
Set xlFile = xlObj.WorkBooks.Open("c:\temp\filename.xls")
'turn off screen alerts
xlObj.Application.DisplayAlerts = False
'loop through sheets
For Each Worksheet In xlFile.Worksheets
'change sheet to desired worksheet name
If Worksheet.Name = "SheetToRename" Then
'get prior workday
dPriorWorkday = xlObj.Application.WorksheetFunction.WorkDay(Now, -1)
'format as necessary (I used ISO 8061)
Worksheet.Name = Year(dPriorWorkday) & "-" & Right("0" & Month(dPriorWorkday),2) & "-" & Right("0" & Day(dPriorWorkday),2)
End If
'change all sheets to desired font
With Worksheet.Cells.Font
.Name = "Verdana"
.Size = 12
End With
Next
'save, close, then quit
xlFile.Close True
xlObj.Quit
部分工作表名称的修订
If Left(Worksheet.Name,12) = "Target Sheet" Then
'get prior workday
dPriorWorkday = xlObj.Application.WorksheetFunction.WorkDay(Now, -1)
'format as necessary (I used ISO 8061)
Worksheet.Name = "Target Sheet " & Year(dPriorWorkday) & "-" & Right("0" & Month(dPriorWorkday),2) & "-" & Right("0" & Day(dPriorWorkday),2)
End If