我创建了一个宏来将我的工作表导出为PDF,但该公司的一些用户使用Mac OS。当这些用户尝试保存时,会给他们一个错误。如何允许Win和Mac用户使用相同的PDF导出?
这是我目前的代码:
Sub CreatePDF()
Dim wksSheet As Worksheet
Set wksSheet = ActiveSheet
wksSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & Range("exportName"), Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
End Sub
答案 0 :(得分:3)
VBA也有Application.PathSeparator。
http://msdn.microsoft.com/en-us/library/office/ff820973%28v=office.15%29.aspx
答案 1 :(得分:0)
我无法在SO上找到答案,但遇到了这种解决方法:
Sub CreatePDF()
Dim wksSheet As Worksheet
Dim TheOS As String
TheOS = Application.OperatingSystem
If InStr(1, TheOS, "Windows") > 0 Then
Set wksSheet = ActiveSheet
wksSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & Range("exportName"), Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
Exit Sub
Else
Set wksSheet = ActiveSheet
wksSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & ":" & Range("exportName"), Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
Exit Sub
End If
End Sub