如何在VBA(Mac)中将文件保存到桌面

时间:2017-05-24 15:35:45

标签: excel vba macos excel-vba

我在VBA中编写一个宏,需要兼容Windows和Mac机器。我需要将文件作为制表符分隔文本文件保存到用户桌面,直到最后一切正常。下面是我尝试的代码,但我一直收到错误。任何帮助表示赞赏。谢谢!

'Export doc as Delimited Text

Dim OS As String
OS = Application.OperatingSystem

Dim un As Variant

un = (Environ$("Username"))

Dim wb As Workbook
Set wb = Workbooks.Add
ThisWorkbook.Sheets("dataExport").Copy Before:=wb.Sheets(1)

If InStr(OS, "Windows") > 0 Then

wb.SaveAs Filename:="C:\Users\" & un & "\Desktop\" & CaseNum & ".txt", FileFormat:=xlText

Else

wb.SaveAs Filename:="/Users/" & un & "/Desktop/" & CaseNum & ".txt", FileFormat:=xlText

End If

1 个答案:

答案 0 :(得分:0)

在Excel中的Mac上,您必须使用:作为分隔符:

wb.SaveAs Filename:="Macintosh HD:Users:" & un & ":Desktop:" & CaseNum & ".txt", FileFormat:=xlText