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

%3CLINGO-SUB%20id%3D%22lingo-sub-2183477%22%20slang%3D%22en-US%22%3EHow%20can%20I%20write%20this%20windows%20code%20into%20Mac%20code%3F%20(VBA)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2183477%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20guys%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20code%20I%20wrote%20under%20is%20the%20one%20I%20used%20when%20I%20had%20Windows%20but%20recently%20I%20changed%20to%20Mac.%20I%20want%20to%20change%20the%20code%20so%20it%20runs%20on%20Mac%20but%20don't%20know%20what%20needs%20to%20be%20changed%20since%20this%20is%20my%20first%20time%20and%20I%20didn't%20find%20any%20information%20on%20internet.%20I%20hope%20if%20anyone%20could%20give%20some%20feedback.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3EIf%20Range(%22F3%22).Value%20%3D%20%22%22%20Then%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Windows(%22Import%20OT.xlsm%22).Activate%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Sheets(%22Cash%22).Select%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Dim%20filename102%20As%20String%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Dim%20path102%20As%20String%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Application.DisplayAlerts%20%3D%20False%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20path102%20%3D%20Environ(%22UserProfile%22)%20%26amp%3B%20%22%5CDropbox%5CA271%5C5%20Oppgjor%5C%22%20%26amp%3B%202021%20%26amp%3B%20%22%5C%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20filename102%20%3D%20Range(%22B1%22).Value%20%26amp%3B%20%22.xlsx%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20ActiveWorkbook.SaveAs%20path102%20%26amp%3B%20Range(%22A2%22)%20%26amp%3B%20%22%5C%22%20%26amp%3B%20Range(%22A1%22)%20%26amp%3B%20%22%20%22%20%26amp%3B%20filename102%2C%20xlOpenXMLWorkbook%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Application.DisplayAlerts%20%3D%20True%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Else%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Cells.Select%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Range(%22F3%22).Activate%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Selection.Copy%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Workbooks.Add%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20ActiveSheet.Paste%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Dim%20Path2%20As%20String%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Dim%20fpathname2%20As%20String%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Path2%20%3D%20Environ(%22UserProfile%22)%20%26amp%3B%20%22%5CDropbox%5CA271%5C4%20Lonnslipper%5C%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20fpathname2%20%3D%20Path2%20%26amp%3B%20Range(%22F3%22)%20%26amp%3B%20%22%5C%22%20%26amp%3B%20Range(%22F2%22)%20%26amp%3B%20%22%20%22%20%26amp%3B%20Range(%22B3%22)%20%26amp%3B%20%22.xlsx%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20ActiveWorkbook.SaveAs%20filename%3A%3Dfpathname2%2C%20FileFormat%3A%3D51%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22x_MsoNormal%22%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20ActiveWorkbook.Close%3CBR%20%2F%3E%3C%2FSPAN%3E%3CBR%20%2F%3EThanks%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2183477%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%20on%20Mac%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2184169%22%20slang%3D%22de-DE%22%3ESubject%3A%20How%20can%20I%20write%20this%20windows%20code%20into%20Mac%20code%3F%20(VBA)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2184169%22%20slang%3D%22de-DE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F571785%22%20target%3D%22_blank%22%3E%40excelnoob298%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fwww.rondebruin.nl%2Fmac.htm%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EExcel%20for%20the%20Mac%20Tips%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMaybe%20this%20information%20will%20help%20you.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENikolino%20%3CBR%20%2F%3E%20The%20more%20I%20know%2C%20the%20more%20I%20realize%20that%20I%20don't%20know%20anything.%3CBR%20%2F%3E(Albert%20Einstein%20freely%20based%20on%20Socrates)%3C%2FP%3E%3C%2FLINGO-BODY%3E
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)