Results 1 to 7 of 7

Thread: Convert VBA Code Designed for Windows To Run On A Mac

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Site Admin VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,496
    Location
    Just had a quick look at something similar from Ron DeBruin at learn.microsoft.com
    Sub Mail_Selection_In_Excel2011()'For Excel 2011 for the Mac and Apple Mail
        Dim Source As Range
        Dim Destwb As Workbook
        Dim wb As Workbook
        Dim TempFilePath As String
        Dim TempFileName As String
        Dim FileExtStr As String
        Dim FileFormatNum As Long
        If Val(Application.Version) < 14 Then Exit Sub
        Set Source = Nothing
        On Error Resume Next
        Set Source = Selection.SpecialCells(xlCellTypeVisible)
        On Error GoTo 0
        If Source Is Nothing Then
            MsgBox "The source is not a range or the sheet is protected, " & _
                   "please correct and try again.", vbOKOnly
            Exit Sub
        End If
        If ActiveWindow.SelectedSheets.Count > 1 Or _
           Selection.Cells.Count = 1 Or _
           Selection.Areas.Count > 1 Then
            MsgBox "An Error occurred :" & vbNewLine & vbNewLine & _
                   "You have more than one sheet selected." & vbNewLine & _
                   "You only selected one cell." & vbNewLine & _
                   "You selected more than one area." & vbNewLine & vbNewLine & _
                   "Please correct and try again.", vbOKOnly
            Exit Sub
        End If
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
        End With
        Set wb = ActiveWorkbook
        Set Destwb = Workbooks.Add(xlWBATWorksheet)
        Source.Copy
        With Destwb.Sheets(1)
            .Cells(1).PasteSpecial Paste:=8
            .Cells(1).PasteSpecial Paste:=xlPasteValues
            .Cells(1).PasteSpecial Paste:=xlPasteFormats
            .Cells(1).Select
            Application.CutCopyMode = False
        End With
        'Save format and extension
        FileExtStr = ".xlsx": FileFormatNum = 52
        ' Or if you want it in xls format, use:
        ' FileExtStr = ".xls": FileFormatNum = 57
        ' Save the new workbook, mail it, and delete it.
        'If you want to change the file name then change only TempFileName
        TempFilePath = MacScript("return (path to documents folder) as string")
        TempFileName = "Selection of " & wb.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")
        With Destwb
            .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
            MailFromMacWithMail bodycontent:="Hi there", _
            mailsubject:="Mail Selection Test", _
            toaddress:="ron@debruin.nl", _
            ccaddress:="", _
            bccaddress:="", _
            attachment:=.FullName, _
            displaymail:=False
           .Close SaveChanges:=False
        End With
        KillFileOnMac TempFilePath & TempFileName & FileExtStr
        With Application
            .ScreenUpdating = True
            .EnableEvents = True
        End With
    End Sub
    Perhaps this may give you some ideas. Notice that he doesn't use vbCrLf but vbNewLine.
    Last edited by Aussiebear; 01-10-2025 at 04:18 AM.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •