Using MacScript to run a line of code in Terminal through VBA

mcomp72

Active Member
Joined
Aug 14, 2016
Messages
305
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I've made a workbook in Excel for Windows, and am now trying to get it to work on Excel for Mac. One option I have given the user is to output certain sheets into a single PDF file. Due to a problem with Excel for Mac, I've had to write code to output each worksheet as a separate PDF file. I now want to merge them together into one PDF file.

I found a blog that explains how to do this in Terminal.
http://cmdlinetips.com/2016/03/how-to-join-pdf-files-in-mac-on-terminal/

I tested it, and figured out how to make it work on my Mac running El Capitan (10.11). In Terminal, I type this and it works:

/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py -o /Users/mattc/Documents/NewPDF.pdf /Users/mattc/Documents/1.pdf /Users/mattc/Documents/2.pdf

Now I want to make it so it does this via VBA code, so the user doesn't have to worry about opening up Terminal and doing it manually. I'm using Excel 2011 for Mac, ver 14.7.7.

I have almost no experience with Mac, so the only things I have tried are things I've seen in other forum posts about possibly how to do it.

I have tried the following, but nothing has worked so far:

Code:
Dim myMacScript As String
Dim Temp

'ATTEMPT [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
myMacScript = "do shell script ""/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py -o /Users/mattc/Documents/NewPDF.pdf /Users/mattc/Documents/1.pdf /Users/mattc/Documents/2.pdf"""

Temp = MacScript(myMacScript)

'Instead of the above line, I also tried this instead:
MacScript (myMacScript)

'but that did not work either.

'ATTEMPT [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=2]#2[/URL] 
myMacScript = "run script (""/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/Resources/join.py -o /Users/mattc/Documents/NewPDF.pdf /Users/mattc/Documents/1.pdf /Users/mattc/Documents/2.pdf"")"

Temp = MacScript(myMacScript)

'ATTEMPT [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=3]#3[/URL] 
myMacScript = "run script (""/System/Library/Automator/Combine\ PDF\  Pages.action/Contents/Resources/join.py -o  /Users/mattc/Documents/NewPDF.pdf /Users/mattc/Documents/1.pdf  /Users/mattc/Documents/2.pdf"" as alias)"

Temp = MacScript(myMacScript)

In all cases, I get Runtime error 5: invalid procedure call or argument.

Anyone have any idea how to make this work?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
After what felt like an eternity of Google searching, I finally figured out what was wrong. Whereever I had the backslash characters, I had to have TWO of them in order for it to work. So the line of code that eventually worked was:

Code:
myMacScript = "do shell script ""/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py -o /Users/mattc/Documents/NewPDF.pdf /Users/mattc/Documents/1.pdf /Users/mattc/Documents/2.pdf"""
 
Upvote 0

Forum statistics

Threads
1,223,630
Messages
6,173,454
Members
452,514
Latest member
cjkelly15

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top