VBA to save to Dropbox on any users computers

Mrsbex

New Member
Joined
Dec 5, 2017
Messages
12
Can any of you clever people out there help me please? I have reached the end of my tether...

I have this code to try and save a workbook as an XLS file to folder in Dropbox using text from the worksheet as a filename. I had it running beautifully on Macs but we are now moving over to PCs and of course the macro is not working...


Code:
Sub SaveIt()
    Dim FName As String
    FName = ActiveWorkbook.Sheets("Data").Range("D2").Value
ActiveWorkbook.SaveAs Filename:="%USERPROFILE%\Dropbox\OPERATIONS\Phone Orders" & FName & ".xls", FileFormat:=xlExcel8


End Sub

When I run it, it tries to apply the Dropbox path twice and loses the end of it too...

The error message I am getting, on my PC for instance, is...

Run-time error '1004':

Microsoft Excel cannot access the file 'C:\Users\Beckey_2\Dropbox\OPERATIONS\Phone Orders\%USERPROFILE%\Dropbox\OPERATIONS\'.

I have tried putting in a ChDir line:
Code:
ChDir "%USERPROFILE%\Dropbox\OPERATIONS\Phone Orders
but then I get:

Run-time error '76':
"Path not found" error message.

What can I do to fix this?

Thanks in advance,
Beckey.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
What is in 'Data'!D2? Does it contain only the filename, or the complete path? Does it ever get overwritten with the path?

I would probably use
Code:
ActiveWorkbook.Worksheets("Data").Cells(2,4).Value
for that, but that should work properly.
 
Upvote 0
Thanks Nutster, I changed it to your suggestion but it doesn't make any difference. It seems to be the path that is the issue :mad: It still takes the path from the last thing you opened, and tries to append the dropbox path stated in the macro to the end of it.

It appears to be taking everything in the quotes literally...

Oh well, I'll keep plodding on till I find a solution :banghead:
 
Upvote 0
How about
Code:
Filename:= Environ("USERPROFILE") & "\Dropbox\OPERATIONS\Phone Orders\"
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,183
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