Microsoft Excel

Ron de Bruin
Excel Automation

Microsoft MVP Program

Check if Disk exist

You can use the macro example below to check if a disk exists or is available on your Mac. Do not forget to copy the function also in your code module.

Note : This is not working in Mac Office 2016 on this moment

Sub TestDisk()
'Also working to check if a Network
'disk is available on your Mac
    MsgBox DiskExistsOnMac("Macintosh HD")
End Sub

Function DiskExistsOnMac(Diskstr As String) As Boolean
'Function to test if a disk exist on a Mac.
'Also working to check if a Network
'disk is available on your Mac
    Dim ScriptToCheckDisk As String
    ScriptToCheckDisk = "tell application " & Chr(34) & "System Events" & Chr(34) & Chr(13)
    ScriptToCheckDisk = ScriptToCheckDisk & "exists disk " & _
                        Chr(34) & Diskstr & Chr(34) & Chr(13)
    ScriptToCheckDisk = ScriptToCheckDisk & "end tell" & Chr(13)
    DiskExistsOnMac = MacScript(ScriptToCheckDisk)
End Function