Need: Start or stop the Onedrive sync client via VBA
Reason: Running a procedure that looped through files and made some changes caused Excel to crash while Onedrive sync client was running
Couldn't find a more "elegant" way to do it, but it works
Adjust the program files folder if you're using 32bit version
' Credits: https://stackoverflow.com/questions/49652606/wscript-shell-to-run-a-script-with-spaces-in-path-and-arguments-from-vba
Private Sub ManageOnedriveSync(ByVal action As Integer)
Dim shell As Object
Set shell = VBA.CreateObject("WScript.Shell")
Dim waitTillComplete As Boolean: waitTillComplete = False
Dim style As Integer: style = 1
Dim errorcode As Integer
Dim path As String
Dim commandAction As String
Select Case action
Case 1
commandAction = "/shutdown"
End Select
path = Chr(34) & "%programfiles%\Microsoft OneDrive\Onedrive.exe" & Chr(34) & " " & commandAction
errorcode = shell.Run(path, style, waitTillComplete)
End Sub
Shutdown:
ManageOnedriveSync 1
Start:
ManageOnedriveSync 0