+ Reply to Thread
Results 1 to 5 of 5

Macro to loop through all files in a folder troubleshooting (excel for mac)

  1. #1
    Registered User
    Join Date
    04-26-2011
    Location
    New Orleans, LA
    MS-Off Ver
    Excel 2011
    Posts
    13

    Macro to loop through all files in a folder troubleshooting (excel for mac)

    Hello,

    I wrote a macro that looped through a folder of workbooks and performed a series of tasks on each one. My problem is that it opens a file called "DS_Store" and I get an error message because excel is unable to perform any of the tasks I need.

    Here is the macro:


    Sub Loopfolder_All_Arizona()


    Dim wbResults As Workbook
    Dim wbCodeBook As Workbook
    Dim strPath As String
    Dim strFile As String
    Dim i As Integer

    With Application
    .ScreenUpdating = False
    .DisplayAlerts = False
    .EnableEvents = False
    End With

    Set wbCodeBook = ThisWorkbook

    'Define the path to your folder
    strPath = "Macintosh HD:Users:TSM:Desktop:TESTLOOP FOLDER:"

    'Ensure that the path ends in a backslash
    If Right(strPath, 1) <> ":" Then strPath = strPath & ":"

    'Call the first file within the folder (change the file extension, accordingly)
    strFile = Dir(strPath & "*.xlsx")

    'Loop through each file within the folder
    Do While Len(strFile) > 0
    'Open the current file
    Set wbResults = Workbooks.Open(strPath & strFile)


    Application.Calculation = xlAutomatic
    Application.Run "'Personal Macro Workbook.xlsb'!Rename_all_worksheets"


    Sheets("Sheet Names").Select
    FPath = "Macintosh HD:Users:TSM:Documents:Convention:Databases:Arizona:Primaries:Counties"
    FName = Sheets("Sheet Names").Range("A2").Text
    ActiveWorkbook.SaveAs Filename:=FPath & ":" & FName
    Application.DisplayAlerts = False
    ActiveWindow.SelectedSheets.Delete
    Application.DisplayAlerts = True
    ActiveWorkbook.save



    ActiveWorkbook.Close


    strFile = Dir

    Loop

    With Application
    .ScreenUpdating = True
    .DisplayAlerts = True
    .EnableEvents = True
    End With
    MsgBox "DONE"
    End Sub

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Macro to loop through all files in a folder troubleshooting (excel for mac)

    The code tag button # is in the Go Advanced button's dialog.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-26-2011
    Location
    New Orleans, LA
    MS-Off Ver
    Excel 2011
    Posts
    13

    Re: Macro to loop through all files in a folder troubleshooting (excel for mac)

    I got a message that said that "Skipit" was not defined

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Macro to loop through all files in a folder troubleshooting (excel for mac)

    Opps, add the GoTo.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-26-2011
    Location
    New Orleans, LA
    MS-Off Ver
    Excel 2011
    Posts
    13

    Re: Macro to loop through all files in a folder troubleshooting (excel for mac)

    Thanks, that worked perfectly.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1