Mac/PC compatible Macro

Paulsondav

New Member
Joined
May 22, 2016
Messages
1
Hey,

I've scowered the internet for a solution but have come up empty with an answer I can actually understand:eeek:. I've had a little cross over trouble with the code below. Although this works perfectly on my PC I found out the Workbook will mainly be used on a MAC which I really have no experience with. It seems that on a MAC the folderpath must be different and keeps coming back with an error saying it cannot find the file path. On the Function open Part I also use the same Filepath call but before it even gets to that it hits a runtime error while setting objWord. Any help on this is much appreciated. Thanks.




Sub ExpandRecords()


Dim folderPath As String

ActiveWorkbook.SaveCopyAs Filename:=folderPath & "\Data.xls"

Call FnOpeneWordDoc


End Sub


Function FnOpeneWordDoc()
'Finds Desktop Path and Opens Mail Template


Dim objWord

Dim objDoc

Dim folderPath As String

folderPath = Application.ActiveWorkbook.Path


Set objWord = CreateObject("Word.Application")


Set objDoc = objWord.Documents.Open(folderPath & "\Mail Template.docm", ReadOnly:=False)


objWord.Visible = True

objWord.Run "Mail_Merge"

End Function
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Macs & PCs do indeed use different path separators. Try something along the lines of:

Code:
Sub ExpandRecords()
Dim folderPath As String
folderPath = ActiveWorkbook.Path & Application.PathSeparator
ActiveWorkbook.SaveCopyAs Filename:=folderPath & "Data.xls"
Call FnOpeneWordDoc(folderPath)
End Sub

Function FnOpeneWordDoc(folderPath As String)
Dim objWord As Object, objDoc As Object
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open(folderPath & "Mail Template.docm", ReadOnly:=False)
objWord.Visible = True
objWord.Run "Mail_Merge"
End Function

For further info on working with files & folders on Macs, see: Working with Files and Folders (Mac)

PS: When posting code, please use the code tags, indicated by the # button on the posting menu.
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

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