How can I write this windows code into Mac code? (VBA)

Contributor

Hi guys 

The code I wrote under is the one I used when I had Windows but recently I changed to Mac. I want to change the code so it runs on Mac but don't know what needs to be changed since this is my first time and I didn't find any information on internet. I hope if anyone could give some feedback. 

If Range("F3").Value = "" Then

    Windows("Import OT.xlsm").Activate

    Sheets("Cash").Select

    Dim filename102 As String

    Dim path102 As String

    Application.DisplayAlerts = False

    path102 = Environ("UserProfile") & "\Dropbox\A271\5 Oppgjor\" & 2021 & "\"

    filename102 = Range("B1").Value & ".xlsx"

    ActiveWorkbook.SaveAs path102 & Range("A2") & "\" & Range("A1") & " " & filename102, xlOpenXMLWorkbook

    Application.DisplayAlerts = True

    Else

    Cells.Select

    Range("F3").Activate

    Selection.Copy

    Workbooks.Add

    ActiveSheet.Paste

    Dim Path2 As String

    Dim fpathname2 As String

    Path2 = Environ("UserProfile") & "\Dropbox\A271\4 Lonnslipper\"

    fpathname2 = Path2 & Range("F3") & "\" & Range("F2") & " " & Range("B3") & ".xlsx"

    ActiveWorkbook.SaveAs filename:=fpathname2, FileFormat:=51

    ActiveWorkbook.Close

Thanks

4 Replies

@excelnoob298 

 

Excel for the Mac Tips

 

Maybe this information will help you.

 

Nikolino
The more I know, the more I realize that I don't know anything.
(Albert Einstein freely based on Socrates)

@excelnoob298 Folder paths on the Mac use forward slashes. Try recording a macro on the Mac, that opens and closes a file on your. Then you'll see how it works on a Mac. Now, re-write your "path" statements to match that format.

I tried this method but there was to much code to write for what I have over. but it seems to work maybe on Mac. I encountered another problem if you could help with it

Path001 = Environ("UserProfile") & "\Dropbox\A271\4 Lonnslipper\" & Range("F3")
Folder = Dir(Path001, vbDirectory)
If Folder = vbNullString Then
VBA.FileSystem.MkDir (Path001)
ActiveWorkbook.SaveAs filename:=fpathname1, FileFormat:=51
ActiveWorkbook.Close
Else
ActiveWorkbook.SaveAs filename:=fpathname1, FileFormat:=51
ActiveWorkbook.Close
End If
the code works for finding if a folder exists or not and then based on this create or not.
This code works fine on windows but on Mac I get error message on this part "VBA.FileSystem.MkDir (Path001)". I checked the link you sent but the code there was to long. if I have to write that code for every sheet I have then that would take me few days to fix. so I was wondering if you could point out what I have to edit here for it to work on Mac vba
thanks
Regarding Mac, unfortunately, I can't help. A beginner is a pro compared to me.
Sorry that I can't help you, but I'm sure that some of the great people and specialists here will take care of your issue.

Thank you for your understanding and patience

Nikolino
I know I don't know anything (Socrates)