2015-10-20 73 views
0

我需要编写一个脚本来将工作表保存到预定位置,并且保存名称是从工作表中的值填充的。我可以将它保存在适当的位置,但文件名返回FATPMetiFolderPath和FATPMetiPath(\ Volumes \ MFS1 \ Groups \ METI ... \ METIman \ MMP- FATP.xlsm)的组合。我可以用Windows Excel VBA来做到这一点,但我之前从未使用过Mac。我在PC上编程,但如果在Mac上使用,则需要能够正确保存。OS X Excel 2011 VBA保存文件名

Sub saveFATPMMMac() 

'Saves copy for access for everyone 
Dim FATPMetiPath As String 
Dim FATPMetiFolderPath As String 


FATPMetiFolderPath = "\Volumes\MFS1\Groups\METI\Quality Control\Function and Acceptance Test Documents\METIman\" 
'FATPMetiFolderPath = "C:\Users\gzapantis\Desktop\" 
FATPMetiPath = FATPMetiFolderPath & _ 
    Sheets("Failure Report").Range("FailReportSN").Text & " - FATP " & ".xlsm" 

ThisWorkbook.SaveAs Filename:=FATPMetiPath 

End Sub 
+0

OS X目录路径有不同的路径分隔符,windows使用'\'但是mac使用':' - 你可以使用'Application.PathSeparator'来代替。其余代码应该在OS X上运行正常 –

+1

@MacroMan':'分隔符用于posix路径。您应该可以使用'/'代替Mac路径的'\'。 – Tom

+0

@Tom - 我尝试了您的建议,并将其保存在仍使用路径和文件名作为文件名的原始文件的位置中。 –

回答

0

我已经解决了这个问题。它用正确的文件名保存在正确的位置。

Sub saveFATPMMMac() 
'Saves copy for access for everyone 
    Dim FATPMetiPath As String 
    Dim FATPMetiFolderPath As String 

If Application.PathSeparator = ":" Then 
    FATPMetiFolderPath = "Volumes:MFS1:Groups:METI:Quality Control:Function and Acceptance Test Documents:METIman:" 
Else 
    FATPMetiFolderPath = "F:\Groups\METI\Quality Control\Function and Acceptance Test Documents\METIman\" 
End If 

FATPMetiPath = FATPMetiFolderPath & _ 
    Sheets("Failure Report").Range("FailReportSN").Text & " - FATP.xlsm" 

ThisWorkbook.SaveAs Filename:=FATPMetiPath 

End Sub 

谢谢你指点我在正确的方向。