Indeed, if you’re calling a shell command directly from VBA on a Mac, you can simplify the command. The Shell function in VBA can directly execute shell commands without needing to wrap them in AppleScript. Here’s a streamlined version to copy a file:
Sub CopyFileToExcelScriptsFolder()
Dim sourceFilePath As String
Dim destinationFolderPath As String
Dim shellCommand As String
' Set the source file path and the destination folder path
sourceFilePath = "/path/to/your/source/file.txt" ' Replace with your source file path
destinationFolderPath = "~/Library/Application Scripts/com.microsoft.Excel/"
' Create the shell command
shellCommand = "cp " & sourceFilePath & " " & destinationFolderPath
' Execute the shell command
Shell "bash -c '" & shellCommand & "'", vbNormalFocus
In this example:
sourceFilePath should be the full path to the file you want to copy.
destinationFolderPath is the path to the destination folder. Make sure the path is correct for your environment.
- The
Shell function is used to execute the cp (copy) command directly in the shell.
- The command is wrapped with
bash -c to ensure it’s executed in the Bash shell.
This approach is more direct and doesn’t involve an additional layer of AppleScript, making it simpler and more efficient for straightforward shell operations like copying a file.
Remember to test this code in a controlled environment, especially if you’re working with important files, to ensure it works as expected.