+ Reply to Thread
Results 1 to 4 of 4

Message box at the end of loop - with a file count if possible

Hybrid View

  1. #1
    Registered User
    Join Date
    01-11-2021
    Location
    Brighton
    MS-Off Ver
    365
    Posts
    85

    Message box at the end of loop - with a file count if possible

    The following code runs various macros on a loop for numerous files (up to 40ish before it tries to run a file for a second time) - any suggestions to increase the number of files? - not the main request, but though it worth asking.

    What I'd like to add is a message box at the end of running all the files in the selected folder, saying it has finished and ideally how many files it has processed. Possible?

    Many thanks for any help


    Sub SN_SWB()
    
        Dim xFd As FileDialog
        Dim xFdItem As Variant
        Dim xFileName As String
        Set xFd = Application.FileDialog(msoFileDialogFolderPicker)
        If xFd.Show = -1 Then
            xFdItem = xFd.SelectedItems(1) & Application.PathSeparator
            xFileName = Dir(xFdItem & "*.xls*")
            Do While xFileName <> ""
                With Workbooks.Open(xFdItem & xFileName)
                    
         
    '
        Application.Calculation = xlCalculationManual
        Application.ScreenUpdating = False
        Application.DisplayStatusBar = False
        Application.DisplayAlerts = False
        
        Application.Run "Add_Cover_Info"
        
        Application.Run "Pre_Data_Format"
        
        Application.Run "Data_Format"
        
        Application.Run "TOC_Column_width"
        
        Application.Run "DR_width"
        
        Application.Run "ID_width"
            
        Application.Run "ORIGIN_DEPART_width"
        
        Application.Run "ORIGIN_width"
        
        Application.Run "ARRIVE_width"
        
        Application.Run "DEPART_width"
            
        Application.Run "DESTINATION_width"
        
        Application.Run "PLT_width"
        
        Application.Run "FAC_width"
        
        Application.Run "CALLING_POINTS_width"
            
        Application.Run "ROW_Autofit"
        
        Application.Run "Header_Margins"
        
        Application.Run "SaveAsA13Cell"
        
        Application.Run "Create_PDF"
        
        Application.Run "Save_Close"
     
    '
        Application.Calculation = xlCalculationAutomatic
        Application.ScreenUpdating = True
        Application.DisplayStatusBar = True
    '
                End With
                xFileName = Dir
            Loop
        End If
    End Sub

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,860

    Re: Message box at the end of loop - with a file count if possible

    Try:
    Sub SN_SWB()
        Dim xFd As FileDialog, xFdItem As Variant, xFileName As String, x As Long
        Set xFd = Application.FileDialog(msoFileDialogFolderPicker)
        If xFd.Show = -1 Then
            xFdItem = xFd.SelectedItems(1) & Application.PathSeparator
            xFileName = Dir(xFdItem & "*.xls*")
            Do While xFileName <> ""
                With Workbooks.Open(xFdItem & xFileName)
                    x = x + 1
                    Application.Calculation = xlCalculationManual
                    Application.ScreenUpdating = False
                    Application.DisplayStatusBar = False
                    Application.DisplayAlerts = False
                    Application.Run "Add_Cover_Info"
                    Application.Run "Pre_Data_Format"
                    Application.Run "Data_Format"
                    Application.Run "TOC_Column_width"
                    Application.Run "DR_width"
                    Application.Run "ID_width"
                    Application.Run "ORIGIN_DEPART_width"
                    Application.Run "ORIGIN_width"
                    Application.Run "ARRIVE_width"
                    Application.Run "DEPART_width"
                    Application.Run "DESTINATION_width"
                    Application.Run "PLT_width"
                    Application.Run "FAC_width"
                    Application.Run "CALLING_POINTS_width"
                    Application.Run "ROW_Autofit"
                    Application.Run "Header_Margins"
                    Application.Run "SaveAsA13Cell"
                    Application.Run "Save_Close"
                    Application.Calculation = xlCalculationAutomatic
                    Application.ScreenUpdating = True
                    Application.DisplayStatusBar = True
                End With
                xFileName = Dir
            Loop
        End If
       MsgBox ("Process completed on " & x & " files.")
    End Sub
    I'm not sure what you mean by:
    any suggestions to increase the number of files
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    01-11-2021
    Location
    Brighton
    MS-Off Ver
    365
    Posts
    85

    Re: Message box at the end of loop - with a file count if possible

    Thanks Mumps1 - worked perfectly

    No worries re the number of files, I'll come back to that if it becomes an issue. It can run over 40 files, but then starts rerunning on files already completed, when there are still other left to run.

    Thanks again

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,860

    Re: Message box at the end of loop - with a file count if possible

    You are very welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 13
    Last Post: 07-08-2018, 05:22 AM
  2. [SOLVED] For Each loop, message box if Nothing
    By Un-Do Re-Do in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 12-22-2017, 12:22 AM
  3. [SOLVED] Message box help with loop
    By Slams in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2016, 09:01 AM
  4. Replies: 1
    Last Post: 11-01-2013, 03:22 PM
  5. Import text file into Excel and using a loop to count unique words within the text
    By mrgriff21 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-24-2013, 03:17 PM
  6. [SOLVED] Message Box Loop Macro
    By ScabbyDog in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-19-2012, 12:31 PM
  7. Error Message in Loop
    By Joe Fish in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-26-2005, 08:40 PM

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