【发布时间】:2018-05-27 11:51:57
【问题描述】:
这是一个很好的。 我可以循环浏览工作簿并在上次保存工作簿的工作表上更改/格式化,但我无法更改/格式化/循环拥有多个工作表的工作簿中的剩余工作表,我的代码将无法工作。
注意:宏从单独的 .xlsm 运行。
这是我当前的代码(3 个子):
Sub DarFormatoExelsEnFolder()
'Revisar todos los archivos xlsx en una carpeta y aplicar formato
definido
Dim wb As Workbook
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Dim FldrPicker As FileDialog
'Optimizar Macro
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
'Definir carpeta destino
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Select A Target Folder"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
myPath = .SelectedItems(1) & "\"
End With
'Si es cancelado
NextCode:
myPath = myPath
If myPath = "" Then GoTo ResetSettings
'Definir extensiones a dar formato
myExtension = "*.xlsx*"
'Definir ruta y extensión
myFile = Dir(myPath & myExtension)
'Revisar todos los archivos en la carpeta
Do While myFile <> ""
'Variable de libro abierto
Set wb = Workbooks.Open(Filename:=myPath & myFile)
'Confirmación de libro abierto
DoEvents
'Cambios al Workbook
WorkSheetChange
'Guardar y cerrar Workbook actual
wb.Close SaveChanges:=True
'Confirmación de libro cerrado
DoEvents
'Proximo libro
myFile = Dir
Loop
'Aviso de fin de ejecución
MsgBox "Operación Completada"
ResetSettings:
'Normalizar excel
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Sub WorkSheetChange()
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
Format
Next WS
End Sub
Sub Format()
'Format certain cells
End Sub
大声表扬“电子表格大师”中的人,他们让我走到了这一步......
【问题讨论】:
标签: excel vba loops directory spreadsheet