• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

open multiple workbooks run a macro save and close

i am trying to write a code but keeps failing
i have a wb called wb1 in folder z:\
i want a macro to open from wb1 wb2 call a macro save and close
then it will open wb3 call the same macro save and close and that is for 9 workbooks
the macro that i want to run is group sheets and save as pdf

[Sub GroupTabs()

Dim x As Integer
ThisWorkbook.Worksheets(1).Select
For x = 2 To ThisWorkbook.Worksheets.Count
Worksheets(x).Select (False)
Next x
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:= _
"Z:\wb2.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
End Sub
Sub AllFiles()
Dim folderPath As String
Dim filename As String
Dim wb As Workbook

folderPath = "Z:\" 'change to suit

If Right(folderPath, 1) <> "\" Then folderPath = folderPath + "\"

filename = Dir(folderPath & "*.xlsm")
Do While filename <> ""
Application.ScreenUpdating = False
Set wb = Workbooks.Open(folderPath & filename)

'Call a subroutine here to operate on the just-opened workbook
Call GroupTabs


filename = Dir
Loop
Application.ScreenUpdating = True
End Sub]


that macro works for all files in the folder but in the folder there is the wb1


[Sub AllFiles()
Dim folderPath As String
Dim filename As String
Dim wb As Workbook

folderPath = "Z:\" 'change to suit

If Right(folderPath, 1) <> "\" Then folderPath = folderPath + "\"

filename = Dir(folderPath & "*.xlsm")
Do While filename <> ""
Application.ScreenUpdating = False
Set wb = Workbooks.Open(folderPath & filename)

'Call a subroutine here to operate on the just-opened workbook
Call GroupTabs


filename = Dir
Loop
Application.ScreenUpdating = True
End Sub]

[
Workbooks("wb2.XLSm").Close SaveChanges:=true]
 
Back
Top