【问题标题】:VBA windows to macVBA windows到mac
【发布时间】:2016-05-19 06:29:05
【问题描述】:

我在我的 Windows PC 上编写了代码,有多个宏/VBA,但为使用 Mac 的人制作了文件。

不知道从哪里开始调整代码,但有人知道以下问题是如何引起的,这将帮助我找到解决方案。我可能使用了 Windows 特定组件。

如果有人能把我推向正确的方向,那就太好了。找到了一些主题: 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

谢谢

【问题讨论】:

  • Mac Office 的哪个版本?

标签: macos vba excel


【解决方案1】:

第一部分应该没有问题+ 因为它不是特定于 Windows 的,对于第二部分 - 您使用“\”作为 PDF 文件的路径分隔符,在 Mac 上,这通常是“:”

要使代码对两者兼容,请改用应用程序值:

strFile = ThisWorkbook.Path & Application.PathSeparator & strFile

+注意:this was OP code at time of answer

【讨论】:

  • 谢谢,这可能有效.. 我怎样才能学会这个?是否有某种“转换页面”?我用一个也有错误的代码替换了上面的第一个代码..知道有什么问题吗?或者我怎么能自己弄清楚?
  • 你不能在 2011 年使用 SearchFormat:=False, ReplaceFormat:=False。这些参数不存在。
  • 啊,这就是问题所在...除了购买 2016 版之外,还有其他解决方法吗?
  • @Rory;我尝试了您的解决方案,但我认为我添加它时出错了。有机会在 Mac 上测试它,但它似乎不起作用......我在上面添加了我的新代码..
猜你喜欢
  • 1970-01-01
  • 2015-11-04
  • 2012-08-12
  • 1970-01-01
  • 2021-09-08
  • 2015-11-25
  • 1970-01-01
  • 2017-09-24
  • 1970-01-01
相关资源
最近更新 更多