Using filepaths in VBA code - files located on DropBox

John Steel

New Member
Joined
Feb 7, 2017
Messages
12
Hello and thanks for considering an issue I'm bringing up.

First off - this is relevant only to files stored on DropBox or, very likely, other cloud storage platforms. And only due to the files being accessed on different computers.

The problem appears to be that Excel typically uses absolute filepaths and, when accessing the file on different computers via DropBox, the local filepath varies based on the computer.

My code has the following line which works great from the "jstee" computer, but return error code 400 on other computers. At the moment I would also like for it to work for "ematt" computer, but, ideally, would like for it to adapt to other computers the file is accessed from.

Not sure it matters, but the line below is utilized in a macro that looks up a referenced .jpeg file from a folder on DropBox and places it in a certain place in the worksheet. The Comp_photos folder is within the base level DropBox folder and the file with the macro is located deeper in the DropBox directory. This file is generated from a template and must be able to access the Comp_photos folder from wherever it is in the DropBox directory.

I've been struggling with this for over a year now and would be elated for any help. Thank you!

Folderpath = "C:\Users\jstee\Dropbox\Comp_photos"
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
You can adapt your code using

Code:
Dim filepath as string 
filepath = environ("USERPROFILE")

Try:

Code:
Dim filepath as string

Filename:= Environ("USERPROFILE") & "\Dropbox\Comp_Photos"
 
Last edited:
Upvote 0
Anyone have any thoughts on this as a possible solution? I saw something like it elsewhere but I've not gotten it to work.

Folderpath = "C:\Users" & Environ("username") & "\Dropbox\Comp_photos"
 
Upvote 0
cant edit above but should be

Code:
Dim Filepath As String

Filepath = Environ("USERPROFILE") & "\Dropbox\Comp_Photos\"

tested and working here
 
Upvote 0
Left it as folderpath and it seems to work fine. Gotta test it on a second computer later tonight.

Thanks Jumbo!
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,182
Members
452,615
Latest member
bogeys2birdies

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