I've tried to add the applications to disable the events, but this still does not suppress the message. Do I simply have something out of place?
Code: Select all
Sub OpenOtherFile()
Dim OneDrivePath As String
Dim wb1 As Workbook: Set wb1 = ActiveWorkbook
Dim wb2 As Workbook
Dim File As Object
Dim strPath As String
Dim strFile As String
Dim strFile2 As String
Application.ScreenUpdating = False
OneDrivePath = ThisWorkbook.Path & "\"
If OneDrivePath Like "https:*" Then
OneDrivePath = Replace(Environ("OneDrive") & "\" & Split(OneDrivePath, "/", 5)(4), "/", "\")
End If
For Each File In CreateObject("Scripting.FileSystemobject").Getfolder(OneDrivePath).Files
If File.Name Like "CBM*" Then
Set wb2 = Workbooks.Open(File)
strPath = File
strFile = Right(strPath, Len(strPath) - InStrRev(strPath, "\"))
strFile2 = Left(strFile, Application.WorksheetFunction.Find(".", strFile) - 1)
wb2.Sheets("Measurement Sheet").Range("D2:I868").SpecialCells(xlVisible).Copy
Application.Goto wb1.Sheets(strFile2).Range("A1"), scroll:=True
wb1.Sheets(strFile2).Range("E2").PasteSpecial (xlPasteValues)
Application.EnableEvents = False
wb2.Close False
Application.CutCopyMode = False
Application.EnableEvents = True
End If
Next File
Application.ScreenUpdating = True
End Sub