A
aehan
Hi everyone
I had a problem where I was placing a custom menu in Word which opens
documents based on templates. Jay Freedman was super, and really helped me
on it, however it's still giving me problems, so I think I must have
explained what I wanted to do wrongly.
The code as it is now is as Jay suggested:
Sub OpenLetter()
Dim strNetworkPath As String
Dim strCPath As String
Dim strFile As String
strNetworkPath = "G:\Documents and Settings\" & Environ("USERNAME") &
"\Application Data\Microsoft\Templates\My Templates"
strCPath = Environ("USERPROFILE") & "\Application
Data\Microsoft\Templates\My Templates"
' Opens document based on letter template
If Dir(strNetworkPath, vbDirectory) <> "" Then
strFile = strNetworkPath & "\Letter.dot"
Else
strFile = strCPath & "\Letter.dot"
End If
On Error GoTo BadTemplate
Documents.Add Template:=strFile, NewTemplate:=False, DocumentType:=0
Exit Sub
BadTemplate:
MsgBox "Couldn't find " & strFile
End Sub
If the user is working with a computer that has a network drive on it there
is no problem at all, but if they are working on a PC that only has a C
drive, they get an error because the code seems to need to see a network
drive - at least it appears that way. If I comment out all the code that
refers to the network, the routine works and finds the template on the C
drive, so the code is all fine, except that I need it to say that if it
cannot find a network drive, then find the template in the C drive. I hope
that makes sense, and that you can tell me what I need to do.
Thanks for everything so far.
Aehan
I had a problem where I was placing a custom menu in Word which opens
documents based on templates. Jay Freedman was super, and really helped me
on it, however it's still giving me problems, so I think I must have
explained what I wanted to do wrongly.
The code as it is now is as Jay suggested:
Sub OpenLetter()
Dim strNetworkPath As String
Dim strCPath As String
Dim strFile As String
strNetworkPath = "G:\Documents and Settings\" & Environ("USERNAME") &
"\Application Data\Microsoft\Templates\My Templates"
strCPath = Environ("USERPROFILE") & "\Application
Data\Microsoft\Templates\My Templates"
' Opens document based on letter template
If Dir(strNetworkPath, vbDirectory) <> "" Then
strFile = strNetworkPath & "\Letter.dot"
Else
strFile = strCPath & "\Letter.dot"
End If
On Error GoTo BadTemplate
Documents.Add Template:=strFile, NewTemplate:=False, DocumentType:=0
Exit Sub
BadTemplate:
MsgBox "Couldn't find " & strFile
End Sub
If the user is working with a computer that has a network drive on it there
is no problem at all, but if they are working on a PC that only has a C
drive, they get an error because the code seems to need to see a network
drive - at least it appears that way. If I comment out all the code that
refers to the network, the routine works and finds the template on the C
drive, so the code is all fine, except that I need it to say that if it
cannot find a network drive, then find the template in the C drive. I hope
that makes sense, and that you can tell me what I need to do.
Thanks for everything so far.
Aehan