Forum Discussion

EmiAle79's avatar
EmiAle79
Copper Contributor
May 22, 2023
Solved

Print with VBA PC vs. MAC

I wrote the code below to be able to print all tabs to PDF except 1,4,5 and 6. In my PC it works perfectly, but when I sent it to a MAC it creates an error. what should I change in the code so it w...
  • NikolinoDE's avatar
    May 22, 2023

    EmiAle79 

    The code you provided should at first glance work on both PC and Mac as it uses standard VBA syntax and does not contain any platform specific commands or functions.

    However, there is one part of the code that could potentially cause an error on a Mac due to differences in file path syntax.

    In the line where you specify the PDF filename, you are currently using a Windows file path format:

    Filename:="C:\tempo.pdf"

    On a Mac, the file path should use the forward slash (/) as the path separator and the appropriate Mac file system syntax. You can modify the file path to work on both PC and Mac by using the Application.PathSeparator property, which automatically adapts to the current platform.

    Here is an updated version of that line:

    Filename:=Application.DefaultFilePath & Application.PathSeparator & "tempo.pdf"

    This will use the default file path on the user's machine and append the filename "tempo.pdf" to it, using the appropriate path separator for the platform.

    With this modification, the code theoretically should work on both PC and Mac without any issues.

    Theoretically, because I do not have a Mac and can try it out.

Resources