I have a subroutine that loops through opening, changing, saving and closing multiple files from a shared OneDrive. I'm running into errors when the subroutine closes and saves the files in the line below.
ActiveWorkbook.Close SaveChanges:=True
The subroutine opens the file in the lines below, which automatically opens files in the desktop app rather than the web app. When the file is saved, it tries to sync with the file on the OneDrive account, causing two issues. First, the file won't close until changes are synced, so the subroutine gets stuck on the close line until the sync is finished. Is there a way to force the code to move on before the workbook is finished saving and closing? I'm not sure if On Error Resume Next will do the trick here since I don't believe the issue will trigger an error.
Application.ScreenUpdating = False
Dim j As Integer
Dim k As Integer
Dim n As Integer
n = Range("AgencyTable").Count / 2 - 1
Dim wbkname() As String
ReDim wbkname(n)
For k = 1 To n Step 1
wbkname(k) = ThisWorkbook.Names("AgencyTable").RefersToRange(k + 1, 1)
Next k
For j = 1 To n Step 1
Dim path As String
path = "<path>" & wbkname(j) & ".xlsm"
Set xl = CreateObject("Excel.Sheet")
Set xlsheet = xl.Application.Workbooks.Open(FileName:=path)
The second issue I'm running into is that the file will occasionally fail to save. I am then prompted to save a copy of the file, and my only options at that point are to save a copy or discard the changes. I'm hoping Applpication.DisplayAlerts = False will force the subroutine to discard the changes. Is this correct?
Users encouter this issue often, but it only seems to occur in a specific scenario I have not been able to identify, so I cannot re-create the issue at this time, making it tough to Debug; therefore, any advice is appreciated.