2016-05-19 45 views
0

我在我的Windows PC上創建了一個代碼,有多個宏的/ VBA,但是用Mac創建了一個文件。VBA windows到mac

不知道在那裏與調整代碼啓動,但有沒有人線索以下問題是如何造成的,這將幫助我找到一個解決辦法。我可能使用的窗口特定組件..

如果有人能把我推在正確的方向,這將是偉大的..有沒有發現幾個主題: http://www.vbaexpress.com/forum/archive/index.php/t-12976.html

,這一次可能是對我的PDF問題的解決方案: Excel VBA code to work on Mac, Create PDF Function

問題1:colomnwidth不工作:

End With 
Columns("A:A").EntireColumn.AutoFit 
Columns("A:A").ColumnWidth = 26 
Columns("C:H").Select 
Selection.ColumnWidth = 4.5 
Columns("J:L").Select 
Selection.ColumnWidth = 11.5 
Columns("I:I").Select 
Selection.ColumnWidth = 16.25 
Columns("B:B").ColumnWidth = 11.5 
Columns("J:L").Select 
Selection.ColumnWidth = 10.25 
Columns("I:I").EntireColumn.AutoFit 

按鈕,使PDF給出「無法創建PDF」

Sub SaveConcept() 
Dim ws As Worksheet 
Dim strPath As String 
Dim myFile As Variant 
Dim strFile As String 
On Error GoTo errHandler 

Range("N8:N9").Select 
    With Selection.Interior 
     .Pattern = xlSolid 
     .PatternColorIndex = xlAutomatic 
     .Color = 5287936 
     .TintAndShade = 0 
     .PatternTintAndShade = 0 
    End With 

ActiveSheet.PageSetup.Orientation = xlLandscape 

Set ws = ActiveSheet 

strFile = Range("J15") _ 
      & Format(Now(), " dd-mm-yyyy") _ 
      & Format(" Concept") _ 
      & ".pdf" 
strFile = ThisWorkbook.Path & "\" & strFile 

myFile = Application.GetSaveAsFilename _ 
    (InitialFileName:=strFile, _ 
     FileFilter:="PDF Files (*.pdf), *.pdf", _ 
     Title:="Select Folder and FileName to save") 

If myFile <> "False" Then 
    ActiveSheet.Range("L1", _ 
    ActiveSheet.Range("L1").End(xlDown).End(xlDown).End(xlDown).End(xlToLeft).End(xlToLeft).End(xlToLeft).End(xlDown)).ExportAsFixedFormat _ 
     Type:=xlTypePDF, _ 
     Filename:=myFile, _ 
     Quality:=xlQualityStandard, _ 
     IncludeDocProperties:=True, _ 
     IgnorePrintAreas:=False, _ 
     OpenAfterPublish:=True 

End If 
exitHandler: 
    Exit Sub 
errHandler: 
    MsgBox "Could not create PDF file" 
    Resume exitHandler 

End Sub 

感謝

+0

哪個版本的Mac的Office? – Rory

+0

Office for Mac 2011 – bart1701

回答

2

不應該有與第一部分+一個問題,因爲它沒有什麼特定的窗口,對於第二部分 - 您使用「\」作爲PDF文件的路徑分隔符,在Mac上,這通常是「:」

要使代碼兼容竹葉提取兩種,使用應用程序,而不是價值:

strFile = ThisWorkbook.Path & Application.PathSeparator & strFile 

+注:this was OP code at time of answer

+0

謝謝,這可能適用。我怎麼學這個?是否有某種「轉換頁面」?我用上面的代碼替換了上面的第一個代碼,那裏有一個錯誤。任何想法最新錯誤?或者我怎麼能自己想出來? – bart1701

+2

您不能在2011年使用'SearchFormat:= False,ReplaceFormat:= False'。這些參數不存在。 – Rory

+0

啊,所以這就是問題......除了購買2016版本之外,是否有工作? – bart1701