VBA - saving to OneDrive

mysticmario

Active Member
Joined
Nov 10, 2021
Messages
323
Office Version
  1. 365
Platform
  1. Windows
I have a master file that at some point saves some sheets into seperate file in OneDrive, the problem is that since 4 users have this OneDrive installed on their PC, each and everyone of us has different path to it.
So in order for my coleagues to be able to save the file I had to make a workaround which provided the path for each user.
VBA Code:
wbnew.SaveAs Filename:=wbaddress & "\" & wbname2 & ".xlsm", _
            FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
wbaddress essentially has a path depending on user saving the file
e.g. For user 1: wbaddress = C:\Users\Projektant\OneDrive - ART-PRO Sp. z o.o\Quotations
for user 2: wbaddress = C:\Users\artpr\OneDrive - ART-PRO Sp. z o.o\Documents\Quotations
etc
is there a way to simply reference default path?
for e.g
VBA Code:
wbnew.SaveAs Filename:=[thisfilepath] & "\" & "Quotations" & "\"  & wbname2 & ".xlsm", _
            FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi mysticmario,

what about using
VBA Code:
environ("UserProfile")
to get the individual part of the path for each user?

Ciao,
Holger
 
Upvote 0
Hi mysticmario,

what about using
VBA Code:
environ("UserProfile")
to get the individual part of the path for each user?

Ciao,
Holger
First time seeing something like this how would you use that?
 
Upvote 0
Hi mysticmario,

as you also have indicated individual paths later on you would need something like

VBA Code:
Dim strUserOD As String
Dim strPart As String

'....

strUserOD = Environ("UserProfile") & "\OneDrive - ART-PRO Sp. z o.o"
Select Case Environ("Username")
  Case "Projektant"
    strPart = "\Quotations\"
  Case "artpr"
    strPart = "\Documents\Quotations\"
  Case Else
    MsgBox "No detailed path known for this user, please add code to make macro work.", vbInformation, "End here"
    Exit Sub
End Select

wbname2.SaveAs Filename:=strUserOD & strPart & wbname2 & ".xlsm", _
                      FileFormat:=xlOpenXMLWorkbookMacroEnabled, _
                      CreateBackup:=False

Ciao,
Holger
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,882
Members
449,097
Latest member
dbomb1414

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