좋은 결과입니다. 워크 북을 반복하고 통합 문서가 마지막으로 저장된 시트에서 변경/형식을 지정할 수 있지만 여러 시트가있는 통합 문서의 나머지 시트를 변경/포맷/루프 할 수는 없습니다. 코드가 작동하지 않습니다.폴더의 통합 문서에서 워크 시트를 반복합니다.
참고 : 매크로는 별도의 .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
의 외침 밖으로, 나를 여기까지를 입수했습니다 ...
여기에 작업 코드 (표준 모듈에 붙여 넣기)입니다. 확실히 폴더의 모든 통합 문서로 이동하여 개별 통합 문서를 닫거나 저장하기 전에 마지막으로 활성화 된 시트의 서식을 지정합니다. –
WS.activate 줄 바꿈이 추가되었습니다. 이 코드를 사용해보고 알려주세요. – devKarthikeyanR