Importing files

jordanburch

Active Member
Joined
Jun 10, 2016
Messages
440
Office Version
  1. 2016
Hi All,

I have the below code. Some of the files are locked for not editing and some have digital signatures, although it doesnt import one of the files without a digital signature nor any locked for editing so I may be wrong. Im wondering if that is the issue. When I run the import it only imports some of the files and not other. Im not sure why. Can anyone help?
VBA Code:
Sub AllFiles()
Application.DisplayAlerts = False
    Application.ScreenUpdating = False
   
    Dim folderPath As String
    Dim Filename As String
    Dim wb As Workbook
    folderPath = "C:\Users\jordan.burch.ctr\Desktop\Cert Statements\" 'contains folder path
    If Right(folderPath, 1) <> "\" Then folderPath = folderPath + "\"
    Filename = Dir(folderPath & "*.xls*")
    Do While Filename <> ""
   
        Application.ScreenUpdating = False
'        On Error Resume Next
        Set wb = Workbooks.Open(folderPath & Filename, IgnoreReadOnlyRecommended:=True)
' Dim myPermission As Office.Permission
'    Set myPermission = ThisWorkbook.Permission
'    myPermission.Enabled = False
         Dim ws As Worksheet
    Dim ClearedSheet As String
    ClearedSheet = ""
    For Each ws In ActiveWorkbook.Worksheets
        If InStr(1, ws.Name, "Cleared", vbTextCompare) Then
            ClearedSheet = ws.Name
            Exit For
        End If
    Next
   If ClearedSheet <> "" Then
'   On Error Resume Next
'    ActiveWorkbook.Sheets(ClearedSheet).Range("Aw2:Aw" & Range("b" & Rows.Count).End(xlUp).Row).Value = Filename
        ActiveWorkbook.Worksheets(ClearedSheet).Range("a2:Aw" & Range("b" & Rows.Count).End(xlUp).Row).Copy
        Workbooks("Certification statement automation").Worksheets("Cleared").Range("b" & Range("b" & Rows.Count).End(xlUp).Row + 1).PasteSpecial
    End If
        Workbooks(Filename).Close True
        Filename = Dir
       
    Loop
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub

Jordan
 
Last edited by a moderator:

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,214,979
Messages
6,122,559
Members
449,089
Latest member
Motoracer88

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