在MAC上的VBA中获取邮件的特定文档

问题描述 投票:0回答:1

我在MAC上,所以即使我知道VBA我也不知道如何在MAC上翻译它。我有这个代码,但我有一个关于路径的问题

我想要一个宏加入此路径中的特定文档(已存在):

Path = "Z:\Reporting\" & ext3 & "\" & ext & " - " & ext2 & ".pdf"

(使用ext1 / 2/3是单元格值)并使用Outlook MAC通过邮件发送。

这是我的代码:

Sub SaveMailRangeAsPDFIn2016()
    Dim FilePathName As String
    Dim strbody As String

        FilePathName = ?


'Create the body text in the strbody string
    strbody = "<FONT size=""3"" face=""Calibri"">"
    strbody = strbody & "Hi there" & "<br>" & "<br>" & _
        "This is line 1" & "<br>" & _
        "This is line 2" & "<br>" & _
        "This is line 3" & "<br>" & _
        "This is line 4"
    strbody = strbody & "</FONT>"


MacExcel2016WithMacOutlookPDF _
    subject:="test", _
    mailbody:=strbody, _
    toaddress:="[email protected]", _
    ccaddress:="", _
    bccaddress:="", _
    displaymail:="yes", _
    accounttype:="", _
    accountname:="", _
    attachment:=FilePathName

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub

与功能:

Function MacExcel2016WithMacOutlookPDF(subject As String, mailbody As String, _
    toaddress As String, ccaddress As String, _
    bccaddress As String, displaymail As String, _
    accounttype As String, accountname As String, _
    attachment As String)
    Dim ScriptStr As String, RunMyScript As String

    ScriptStr = subject & ";" & mailbody & ";" & toaddress & ";" & ccaddress & ";" & _
                bccaddress & ";" & displaymail & ";" & accounttype & ";" & _
                accountname & ";" & attachment

    'Call the RDBMacOutlook.scpt script file with the AppleScriptTask function
    RunMyScript = AppleScriptTask("RDBMacOutlook.scpt", "CreateMailInOutlook", CStr(ScriptStr))


End Function
excel vba excel-vba excel-vba-mac
1个回答
1
投票

MacOS / OSX使用与Windows "\"不同的路径分隔符。

所以,如果你的路径在VBA中硬编码,就像这样

Path = "Z:\Reporting\" & ext3 & "\" & ext & " - " & ext2 & ".pdf"

您可以检查操作系统并使用

If Application.OperatingSystem Like "*Mac*" Then
    Path = "your mac path"
Else
    Path = "Z:\Reporting\" & ext3 & "\" & ext & " - " & ext2 & ".pdf"
End If

请注意,Application.PathSeparator返回操作系统使用的实际路径分隔符。

© www.soinside.com 2019 - 2024. All rights reserved.