0

I made a code on my Windows PC, have multiple macro's/VBA's but made the file for somebody with an Mac.

not sure where to start with adjusting code, but has anyone a clue how the following problems are caused, this will help me with finding a solution.. I probably used windows specific components..

if somebody can push me in the right direction, it would be great.. Have found a few topics: http://www.vbaexpress.com/forum/archive/index.php/t-12976.html

and this one probably has the solution for my PDF problem: Excel VBA code to work on Mac, Create PDF Function

Problem 1: colomnwidth doesn't work:

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

Button to make PDF gives "Could not Create 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

thanks

SierraOscar
  • 17,507
  • 6
  • 40
  • 68
bart1701
  • 65
  • 1
  • 10

1 Answers1

2

There shouldn't be an issue with the first part+ as it's nothing specific to windows, for the second part - you're using "\" as the path separator for the PDF file, on a Mac this is typically ":"

To make the code compatible for both, use the application value instead:

strFile = ThisWorkbook.Path & Application.PathSeparator & strFile

+note: this was OP code at time of answer

Community
  • 1
  • 1
SierraOscar
  • 17,507
  • 6
  • 40
  • 68
  • Thanks, this probably works.. How can I learn this? is there some kind of 'conversion page'? I replaced the first code above with a piece where there is a error as well.. any idea whats wrong? or how I can figure it out myself? – bart1701 May 19 '16 at 08:33
  • 2
    You can't use `SearchFormat:=False, ReplaceFormat:=False` on 2011. Those parameters don't exist. – Rory May 19 '16 at 08:44
  • ah, so that's the issue... is there a work around except from buying the 2016 version? – bart1701 May 19 '16 at 09:06
  • @Rory; i tried your solution but i think i made a mistake adding it. had the chance to test it on a Mac but it seems that it doesnt work... I added my new code above.. – bart1701 Jun 01 '16 at 11:50