0

I am trying to attach a template (-.dotm file) to a Word 2011 (Mac) document via VBA. The template is located on a windows network drive (file://BF-02004/Users/A500579/PublicWordTemplate). There are absolutely no restrictions on this share, there is no problem browsing it with Mac - Finder either.

My problem is, how should I address this network share directly from my VBA code?

Here is an code excerpt on what I have tried to show what I mean:

Option Explicit

'these are options which I have tried
Private Const MAC_STYLE_RELATIVE_NETWORK_PATH_TO_TEMPLATE As String = "smb://BF-02004/Users/A500579/PublicWordTemplate/Core.dotm"
'Private Const MAC_STYLE_RELATIVE_NETWORK_PATH_TO_TEMPLATE As String = "smb:BF-02004:Users:A500579:PublicWordTemplate:Core.dotm"
'Private Const MAC_STYLE_RELATIVE_NETWORK_PATH_TO_TEMPLATE As String = "BF-02004:Users:A500579:PublicWordTemplate:Core.dotm"
'Private Const MAC_STYLE_RELATIVE_NETWORK_PATH_TO_TEMPLATE As String = "BF-02004/Users/A500579/PublicWordTemplate/Core.dotm"

Public Sub LoadTemplate()

    'check if file exists (the boolean function FileExists() is defined in another module)
    If FileExists(MAC_STYLE_RELATIVE_NETWORK_PATH_TO_TEMPLATE) Then
        ActiveDocument.AttachedTemplate = MAC_STYLE_RELATIVE_NETWORK_PATH_TO_TEMPLATE
    Else
        MsgBox "The template was NOT found!"
        Exit Sub
    End If

End Sub

What is the correct way to address a windows share from inside a Word 2011 - VBA application?

Hauns TM
  • 1,909
  • 2
  • 22
  • 38

1 Answers1

1

This should be a comment, but it's too long and there's code:

So far, I have been unable to find a syntax that works.

AFAICS you have to use the .Template property of the wdDialogToolsTemplates built-in Dialog, and what you actually need is the colon-separated path from the share name downwards, e.g. in your example, I think you would need to base your code around something like this:

Sub AttachT()
Dim d As Word.Dialog
Set d = Word.Dialogs(wdDialogToolsTemplates)
d.Template = "Users:A500579:PublicWordTemplate:Core.dotm"
d.Execute
Set d = Nothing
End Sub

(If you aren't familiar with the late-bound properties of Word's Built-in dialog boxes, you can find out a little more here - you won't see them in the Object browser in the VB Editor.)

The problem with this is obviously that there can be more than one server with a "Users" share on it. AFAICS, on Mac, Windows/SMB shares are mounted by default under /Volumes and if necessary are given a different name (e.g. if you have two Users shares on different computers, you may see /Volumes/Users and /Volumes/Users-1 . The problem is that also you can specify the template using "Volumes:Users:A500579:PublicWordTemplate:Core.dotm", you can't actually use the equivalent "Volumes:Users-1:" string. So right now I don't see how you can specify the SMB share referenced by Users-1.I think you would either have to rename the share (or, probably more practical, specify an additional Share name), or you may be able to mount the share at a different location in the Mac file structure using the mount command or whatever. However, from what I have seen so far, I am not convinced that last option would work.

Another way that originally looked promising was to use ChangeFileOpenDirectory first, then specify the template via

ActiveDocument.AttachedTemplate = "Core.dotm"

or some such. I can use

ChangeFileOpenDirectory "Users:"

to change to the share that Mac has mounted at /Volumes/Users, but I only seem to be able to specify a template in the top level foler of that share, i.e.

ChangeFileOpenDirectory "Users:"
ActiveDocument.AttachedTemplate = "Core.dotm"

might work for BF-02004:Users:Core.dotm, but the following (and a few variations I tried) do not seem to work:

ChangeFileOpenDirectory "Users:"
ActiveDocument.AttachedTemplate = "A500579:PublicWordTemplate:Core.dotm"

or

' The first line works
ChangeFileOpenDirectory "Users:A500579:PublicWordTemplate:"
ActiveDocument.AttachedTemplate = "Core.dotm"
  • Thanks for trying to help me. There are many really big differences between Word 2010 and Word 2011 when it comes to details. Of course, Windows and Mac are also totally different environments when speaking in terms of referring to network shares. An idea that just popped up was if I could distribute the template from a webserver? I mean, something like `ActiveDocument.AttachedTemplate = "http://myDomain.com/Core.dotm"`? I mean, Mac and Windows... Don't they treat URLs in a similar way? Well, I think I at least should try the idea. It couldn't be worse. :-) – Hauns TM Mar 27 '14 at 13:03
  • I agree about the differences. Re. the webserver, as you say, you can but try. –  Mar 27 '14 at 14:40