Using Environment Variable in Template path 
Author Message
 Using Environment Variable in Template path

I want to create a new document which has a template attache. The template
is in a Folder which should be dynamic. Now the thing is when an other user
wants to open the document and has an other folder with the template in it,
it wont work. So i thought i make a Environment Variable which points to the
folder with the templates (in expl. %myapp_home%). Now i would like to open
the new documents (they are opened within VBA Documents.add) and i want to
use the Variable so that when the other user opens the document, word
matches the Variable to the other path (correct for that user) and finds the
template! is that possible?? it didn't work with
call Documents.Add("%myapp_home%\ATemplate.dot")

can anybody help me, or does anyone have a better idea or way to do it??

thank's a lot

simon



Fri, 29 Oct 2004 17:27:47 GMT  
 Using Environment Variable in Template path
Hi, Simon,

VBA has an Environ function to get the value of an environment string. Try something like this:

Dim oDoc As Document
Dim myHomePath As String

' try to get string from environment
myHomePath = Environ("my_home")

' check whether you got anything
If (Len(myHomePath) = 0) Then
    MsgBox "Environment string my_home" & vbCr & _
    " is empty or does not exist", vbOKOnly, "Error"
    Exit Sub
End If

' make sure it ends with backslash
If (Right(myHomePath, 1) <> "\") Then
    myHomePath = myHomePath & "\"
End If

' add template name to end of path
' to open document
Set oDoc = Documents.Add(Template:=myHomePath & _
    "ATemplate.dot")

--
Regards,
Jay Freedman
Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word

Quote:

> I want to create a new document which has a template attache. The template
> is in a Folder which should be dynamic. Now the thing is when an other user
> wants to open the document and has an other folder with the template in it,
> it wont work. So i thought i make a Environment Variable which points to the
> folder with the templates (in expl. %myapp_home%). Now i would like to open
> the new documents (they are opened within VBA Documents.add) and i want to
> use the Variable so that when the other user opens the document, word
> matches the Variable to the other path (correct for that user) and finds the
> template! is that possible?? it didn't work with
> call Documents.Add("%myapp_home%\ATemplate.dot")

> can anybody help me, or does anyone have a better idea or way to do it??

> thank's a lot

> simon



Fri, 29 Oct 2004 22:58:42 GMT  
 Using Environment Variable in Template path
hey jay,
thank's...
but i can't solve the problem with this. The thing is that when the next
user comes and want's to open the same document with another environment
variable it won't work.... i need to get a variable into the path of the
template which is attached.
Word should then map the variable it self! do u  understand my problem??

thank's

simon



Quote:
> Hi, Simon,

> VBA has an Environ function to get the value of an environment string. Try

something like this:
Quote:

> Dim oDoc As Document
> Dim myHomePath As String

> ' try to get string from environment
> myHomePath = Environ("my_home")

> ' check whether you got anything
> If (Len(myHomePath) = 0) Then
>     MsgBox "Environment string my_home" & vbCr & _
>     " is empty or does not exist", vbOKOnly, "Error"
>     Exit Sub
> End If

> ' make sure it ends with backslash
> If (Right(myHomePath, 1) <> "\") Then
>     myHomePath = myHomePath & "\"
> End If

> ' add template name to end of path
> ' to open document
> Set oDoc = Documents.Add(Template:=myHomePath & _
>     "ATemplate.dot")

> --
> Regards,
> Jay Freedman
> Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word




- Show quoted text -

Quote:
> > I want to create a new document which has a template attache. The
template
> > is in a Folder which should be dynamic. Now the thing is when an other
user
> > wants to open the document and has an other folder with the template in
it,
> > it wont work. So i thought i make a Environment Variable which points to
the
> > folder with the templates (in expl. %myapp_home%). Now i would like to
open
> > the new documents (they are opened within VBA Documents.add) and i want
to
> > use the Variable so that when the other user opens the document, word
> > matches the Variable to the other path (correct for that user) and finds
the
> > template! is that possible?? it didn't work with
> > call Documents.Add("%myapp_home%\ATemplate.dot")

> > can anybody help me, or does anyone have a better idea or way to do it??

> > thank's a lot

> > simon



Sun, 31 Oct 2004 16:48:36 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. setting the path environment variable

2. How to set Environment Variable (PATH) with VB

3. Setting the System Path & Other Environment Variables

4. setting PATH environment variable from VB 3.0 for Windows Pro

5. Expanding SYSTEM %PATH% with embedded SYSTEM environment variable problem

6. WINNT, and PATH environment variables

7. using VB5 to Access Variables in the Normal Template In Word

8. Creating and environment variable and using it in the same cmd window

9. Creating and environment variable and using it in the same cmd window

10. Using Environment Variables

11. Using Environment Variables???

12. Using API to retrieve environment variables?

 

 
Powered by phpBB® Forum Software