Open Word with Document

I want to open MS Word on the Mac with a document.

I can get Word to open, but the document won’t open with it by default.

Here’s my code.

'---- NOTE - cHowTo is the name of the document I want to open and is a parameter of the function

var f_HowToFolder, f_Word As FolderItem
f_HowToFolder = SpecialFolder.Resources.Parent
f_HowToFolder = f_HowToFolder.Parent
f_HowToFolder = f_HowToFolder.Parent
f_HowToFolder = f_HowToFolder.Child(“HowTos”).Child(cHowTo)

f_Word = SpecialFolder.Applications.Child(“Microsoft Word.app”)
f_Word.Open(f_HowToFolder.NativePath)

This opens Word but does not open the document passed to it?

Solved it.

Just needed to change the cHowTo file from a PDF to a DOCX extension and the folderitem.open then opens it with Word.

Code like this is OK you have are certain that “HowTos” folder exists, if it doesn’t you will get a Nill Object exception generated by the “.Child(cHowTo)”.

Unfortunately, I no longer have MS Office available. I used to open a Word document (template) in the following way:

#if TargetWindows
  var oWord               as WordApplication
  var oDoc                as WordDocument
  
  // Document-Creation:
  
  'Start Word and open the document template.
  oWord = new WordApplication
  oWord.Visible = false
  oDoc = oWord.Documents.Add(iv_Template,false)   


Where iv_Template holds the path and the file. For example /Users/mic/workspace/AutoDoc/Templates/MyTemplate.docm

With oWord.Visible you can control whether Word is visible or not.

Oh sorry, I just see that a solution is sought on the Mac :woozy_face: