VPA Filepath for both Desktop and Mac

AndrewDrewAndy

New Member
Joined
Nov 18, 2019
Messages
16
I am running this code and it works well on desktop, but I am not able to run this on Mac. Is there a way to make the path work for both desktop and mac? See code below.

Thank You!


Sub AndrewDrew()
Dim Ary As Variant
Dim i As Long
Dim Pth As String

Pth = Sheets("Master Data").Range("A1")
If Not Right(Pth, 1) = "\" Then Pth = Pth & "\"
Ary = Array("Export 1", "Export 2", "Export 4")
For i = 0 To UBound(Ary)
Sheets(Ary(i)).Copy
With ActiveWorkbook
.SaveAs Pth & Range("C5").Value, 51
.Close False
End With
Next i
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Are you using a valid Mac path in A1 on Master Data?

If you are then the problem might only be the '\' and you can replace that with Application.PathSeparator.
VBA Code:
If Not Right(Pth, 1) = Application.PathSeparator Then Pth = Pth & Application.PathSeparator
 
Upvote 0
Are you using a valid Mac path in A1 on Master Data?

If you are then the problem might only be the '\' and you can replace that with Application.PathSeparator.
VBA Code:
If Not Right(Pth, 1) = Application.PathSeparator Then Pth = Pth & Application.PathSeparator
Will this work for both "\" and "/" file separators? And, what must a mac path start with (eg., desktop is C:xxx\xxx)?

Thank you!
 
Upvote 0
Is the folder you want to save the files to relative to the folder the original file is in?
 
Upvote 0
How are you setting the path in A1 in 'Master Data'?

Paths for Windows and Mac are quite different, here are examples of both with Unix thrown in as well.


Operating SystemExample Path
Windows​
C:\myfolder\mydocument.txt​
Mac OS​
Hard Drive:My Folder:My Document​
Unix​
/usr/myuser/mydocument.txt​
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,893
Members
449,194
Latest member
JayEggleton

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