excel - 将边框应用于文件夹中所有 excel 文件的宏
问题描述
我对 VBA/MACRO 非常陌生,我正在尝试创建一个宏,将边框放置/应用到文件夹中存在的所有 excel 文件。
解决方案
试试这个:
Dim FolderPath As String
Dim StrFile As String
' Put your folder path here
FolderPath = "C:\Temp"
Dim xlWB As Excel.Workbook, xlWS As Excel.Worksheet
StrFile = Dir(FolderPath)
Do While Len(StrFile) > 0
' Basic check that this is a spreadsheet
If Right(StrFile, 5) = ".xlsx" Then
Set xlWB = Workbooks.Open(FolderPath & "/" & StrFile)
For Each xlWS In xlWB.Worksheets
If xlWS.Name = "POL" Or xlWS.Name = "POD" Then
With xlWS.UsedRange
With .Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.Weight = xlThick
End With
End With
End If
Next
xlWB.Close SaveChanges:=True
End If
StrFile = Dir()
Loop
您应该考虑更好地检查和验证您找到的文件实际上是 Excel 工作簿。
推荐阅读
- r - R:使用不同方法计算两个向量之间的欧几里得距离时结果不同
- jenkins - 如何通过 Jenkins 在 k8 Cluster 中部署 K8 应用程序?
- web-scraping - Jsoup 解析多个网站以获取今天发布的链接
- java - 启动时出现 Thymeleaf 错误
- javascript - 未能执行目标 com.github.eirslett:frontend-maven-plugin:1.6:install-node-and-npm(安装节点和 npm)
- powershell - 使用 Get-ADUser 按两个属性过滤
- html - 在容器内居中旋转的 div
- javascript - 在与 webpack 反应中导入 react-leaflet 返回错误
- sql - 你如何在 col3 共享/重叠 col2 的地方返回 col2?
- python - Keras:有没有一种简单的方法可以在 epoch 之间对数据进出训练集进行变异(洗牌)?