Does OneDrive exist?

NdNoviceHlp

Well-known Member
Joined
Nov 9, 2002
Messages
3,623
Determining if OneDrive exists on a pc seems like it would be fairly straight forward with something like this...
Code:
Sub T1Drv()
'test for onedrive
Dim FLName As String
FLName = Environ("OneDrive") & "\"
If Len(Dir(FLName, vbDirectory)) = 0 Then
MsgBox "No OneDrive Available " & Len(Dir(FLName, vbDirectory))
Else
MsgBox "OneDrive is Available " & Len(Dir(FLName, vbDirectory))
End If
End Sub
Not so much. It "seems" to work on newer versions of Windows both connected and not connected to the net, but for my old Vista version that's not connected to the net (if that matters?), it returns "OneDrive is Available 8" (8 is the Len of the Dir return). The problem is that there is no OneDrive on my old Vista Windows pc. I also trialed using the file system objects with .driveexists, folderexists, etc. without any Vista success. You can determine from the registry if OneDrive exists but I would prefer to either use a filesystem object, DIR or something else if anyone has any suggestions. Thanks for your time. Dave
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I'm actually glad you posted this question. I've never seen OneDrive used in Environ before and I didn't know you could do that.
I can't actually test this because I don't have a computer without OneDrive connected but it seems like you could test to see if the Environ("OneDrive") returned anything. This returns TRUE/FALSE

VBA Code:
Function HasOneDrive() As Boolean
On Error Resume Next
HasOneDrive = (Environ("OneDrive") <> "")
End Function

which you could use in a Sub like this if you wanted:

VBA Code:
Sub test()
If HasOneDrive Then
    MsgBox "OneDrive Exists"
Else
    MsgBox "OneDrive does not exist"
End If
End Sub
 
Upvote 0
Solution
Well Scott, my old Vista liked that one. The function worked across varied OS's and XL versions. The code I posted was Google "supported" and not of my own creation. Just one more reason to continue my hatred for the Dir function. Thanks so much for you interest and time. Have a nice day. Dave
 
Upvote 0

Forum statistics

Threads
1,215,109
Messages
6,123,136
Members
449,098
Latest member
Doanvanhieu

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