How do macros handle/interface with popup boxes/message boxes

powercell99

Board Regular
Joined
May 14, 2014
Messages
75
I have a macro that is supposed to copy the contents of a SharePoint folder to my C:drive,
HTML:
Sub CopyWorkbooks()
 
'Note: If ToPath folder ("C:\Aggregation\") already exist it will overwrite existing files in this folder
'if ToPath does not exist, it will be made for you.
    Dim FSO As Object
    Dim FromPath As String
    Dim ToPath As String
 
    FromPath = "//collab.DOUSA.gov/sites/gtomo/bes/mab/ads/trackingsheets/"  ' <--- location of the files being copied
    ToPath = "C:\Aggregation\" ' <--- location where copied files will be pasted
 
    If Right(FromPath, 1) = "\" Then
        FromPath = Left(FromPath, Len(FromPath) - 1)
    End If
 
    If Right(ToPath, 1) = "\" Then
        ToPath = Left(ToPath, Len(ToPath) - 1)
    End If
 
    Set FSO = CreateObject("scripting.filesystemobject")
 
    If FSO.FolderExists(FromPath) = False Then
        MsgBox FromPath & " doesn't exist"
        Exit Sub
    End If
 
    FSO.CopyFolder Source:=FromPath, Destination:=ToPath
       

 
End Sub

But it was crashing and not completing the copying, so i noticed something when i MANUALLY copy and past the folder to my C:Drive; I get 7 Pop up messages that i must click "SKIP" in order to proceed. I think that is whats causing my macro to get hung up and crash, because it doesnt know how to handle the dialog box and Excel is waiting on a user response. The messages are all similar: what code can i add to the macro to instruct it to Choose SKIP when any dialog box appears while its running the macro?

Msg1:
You need permission to perform this action

You require permission from the computer's administrator to make changes to this file

DispForm.ASPX
Type: ASPX File
Size: 13.29KB
Date modified: 6/3/2014 5:38 PM

Try Again Skip Cancel

Do this for all current items
---------------------------
Msg2:
You need permission to perform this action

You require permission from the computer's administrator to make changes to this file

Thumbnails.ASPX
Type: ASPX File
Size: 3.29KB
Date modified: 6/3/2014 5:38 PM

Try Again Skip Cancel

Do this for all current items
----------------------------------------
Msg3:
You need permission to perform this action

You require permission from the computer's administrator to make changes to this file

Upload.ASPX
Type: ASPX File
Size: 3.29KB
Date modified: 6/3/2014 5:38 PM

Try Again Skip Cancel

Do this for all current items
-----------------------------------------
Msg4:
You need permission to perform this action

You require permission from the computer's administrator to make changes to this file

Combine.ASPX
Type: ASPX File
Size: 13.29KB
Date modified: 6/3/2014 5:38 PM

Try Again Skip Cancel

Do this for all current items
-----------------------------------------
Msg5:
You need permission to perform this action

You require permission from the computer's administrator to make changes to this file

Repair.ASPX
Type: ASPX File
Size: 13.29KB
Date modified: 6/3/2014 5:38 PM

Try Again Skip Cancel

Do this for all current items
-------------------------------------------
Msg6:
You need permission to perform this action

You require permission from the computer's administrator to make changes to this file

EditForm.ASPX
Type: ASPX File
Size: 13.29KB
Date modified: 6/3/2014 5:38 PM

Try Again Skip Cancel

Do this for all current items
---------------------------------------------
Msg7:
You need permission to perform this action

You require permission from the computer's administrator to make changes to this file

AllItems.ASPX
Type: ASPX File
Size: 13.29KB
Date modified: 6/3/2014 5:38 PM

Try Again Skip Cancel

Do this for all current items
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
The usual way to switch off pop-ups is to set Appplication.DisplayAlert = False.

When I code this I like to insert an error trap to ensure the application settings are reset before the code ends. See hightlighed (red) lines below.

Rich (BB code):
Sub CopyWorkbooks()
 
'Note: If ToPath folder ("C:\Aggregation\") already exist it will overwrite existing files in this folder
'if ToPath does not exist, it will be made for you.
    Dim FSO As Object
    Dim FromPath As String
    Dim ToPath As String
 
   'ensure applications setting are restored before the code ends
   On Error GoTo errHandler
   Application.DisplayAlerts = False
   
    FromPath = "//collab.DOUSA.gov/sites/gtomo/bes/mab/ads/trackingsheets/"  ' <--- location of the files being copied
    ToPath = "C:\Aggregation\" ' <--- location where copied files will be pasted
 
    If Right(FromPath, 1) = "\" Then
        FromPath = Left(FromPath, Len(FromPath) - 1)
    End If
 
    If Right(ToPath, 1) = "\" Then
        ToPath = Left(ToPath, Len(ToPath) - 1)
    End If
 
    Set FSO = CreateObject("scripting.filesystemobject")
 
    If FSO.FolderExists(FromPath) = False Then
        MsgBox FromPath & " doesn't exist"
        Exit Sub
    End If
 
    FSO.CopyFolder Source:=FromPath, Destination:=ToPath
       


errHandler:
   Application.DisplayAlerts = True
End Sub
 
Upvote 0
Bertie....... SWEET!!!! It works like a CHARM! Thanks very much for taking the time to review the code and give your recommendation. I'm sure i'll use the display alerts & error handler code in many of my macros. I really appreciate it!

Larry
 
Upvote 0

Forum statistics

Threads
1,215,227
Messages
6,123,745
Members
449,116
Latest member
alexlomt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top