I am attempting to copy some custom Office Templates into user profiles when
they log on to the computer. I want it to look to see if the files exist and
if they don't then copy the files from a network share. Here is the Code I
have come up with.

path=CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%\Application Data\Microsoft\Templates\")
dim objFSO
set objFSO=CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("path") = False Then
objFSO.CopyFile "\\servername\stdapps\custemp\*.docx", path
End If

I am getting an error file not found on line 5 character 1 code 800A0035.
I've checked and templates are there. Any ideas?

Any Help would be greatly appreciated

Re: Copy file from server share to user profile by Pegasus

Pegasus
Wed Jul 02 15:04:18 CDT 2008


"Lord Dark Helmet" <LordDarkHelmet@discussions.microsoft.com> wrote in
message news:C7AC2154-25AA-4993-9290-6609A76C03F1@microsoft.com...
>I am attempting to copy some custom Office Templates into user profiles
>when
> they log on to the computer. I want it to look to see if the files exist
> and
> if they don't then copy the files from a network share. Here is the Code I
> have come up with.
>
> path=CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%\Application
> Data\Microsoft\Templates\")
> dim objFSO
> set objFSO=CreateObject("Scripting.FileSystemObject")
> If objFSO.FileExists("path") = False Then
> objFSO.CopyFile "\\servername\stdapps\custemp\*.docx", path
> End If
>
> I am getting an error file not found on line 5 character 1 code 800A0035.
> I've checked and templates are there. Any ideas?
>
> Any Help would be greatly appreciated
>

I am confused by this line of code:

If objFSO.FileExists("path") = False Then

You check for the existence of a file called "path". Since you
surround 'path' with double quotes, the interpreter will take it
as a literal string. Did you perhaps want to write this:

If objFSO.FileExists(path) = False Then

This would still be confusing because the variable 'path'
resolves to a folder, not a file! Should the statment read

If objFSO.FolderExists(path) = False Then

There is also a small inconsistency: While you declare objFSO,
you don't declare the variable 'path'. Declaring all variables while
debugging is a good habit. It should be complemented by having
'option explicit' as your very first statement.



Re: Copy file from server share to user profile by Tom

Tom
Wed Jul 02 15:19:55 CDT 2008

On Jul 2, 3:43 pm, Lord Dark Helmet
<LordDarkHel...@discussions.microsoft.com> wrote:
> I am attempting to copy some custom Office Templates into user profiles when
> they log on to the computer. I want it to look to see if the files exist and
> if they don't then copy the files from a network share. Here is the Code I
> have come up with.
>
> path=CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%\Application Data\Microsoft\Templates\")
> dim objFSO
> set objFSO=CreateObject("Scripting.FileSystemObject")
> If objFSO.FileExists("path") = False Then
> objFSO.CopyFile "\\servername\stdapps\custemp\*.docx", path
> End If
>
> I am getting an error file not found on line 5 character 1 code 800A0035.
> I've checked and templates are there. Any ideas?
>
> Any Help would be greatly appreciated

First, take the quotes from around the variable's name in line five.
With the quotes, you are passing the literal string, path, to the
FileExists method.

Once you fix that, a second problem will arise; specifically, you are
passing a folder's path to a function that can only test for a file.
If you want to test for the presence of the folder, then change the
request to FolderExists, instead. However, I don't think that's what
you want either, because if it were the absence of the folder you were
checking, the next step when it returned False would be to create the
folder - which you are not doing.

So, which is it? File or folder?

If it's the absence of the folder that it to trigger the action, then
try this ...

path=CreateObject("WScript.Shell")_
.ExpandEnvironmentStrings("%UserProfile%") _
& "\Application Data\Microsoft\Templates")
dim objFSO
set objFSO=CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(path) = False Then
objFSO.CreateFolder path
objFSO.CopyFile "\\servername\stdapps\custemp\*.docx", path & "\"
End If

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Re: Copy file from server share to user profile by LordDarkHelmet

LordDarkHelmet
Thu Jul 03 10:40:01 CDT 2008

"Tom Lavedas" wrote:

> On Jul 2, 3:43 pm, Lord Dark Helmet
> <LordDarkHel...@discussions.microsoft.com> wrote:
> > I am attempting to copy some custom Office Templates into user profiles when
> > they log on to the computer. I want it to look to see if the files exist and
> > if they don't then copy the files from a network share. Here is the Code I
> > have come up with.
> >
> > path=CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%\Application Data\Microsoft\Templates\")
> > dim objFSO
> > set objFSO=CreateObject("Scripting.FileSystemObject")
> > If objFSO.FileExists("path") = False Then
> > objFSO.CopyFile "\\servername\stdapps\custemp\*.docx", path
> > End If
> >
> > I am getting an error file not found on line 5 character 1 code 800A0035.
> > I've checked and templates are there. Any ideas?
> >
> > Any Help would be greatly appreciated
>
> First, take the quotes from around the variable's name in line five.
> With the quotes, you are passing the literal string, path, to the
> FileExists method.
>
> Once you fix that, a second problem will arise; specifically, you are
> passing a folder's path to a function that can only test for a file.
> If you want to test for the presence of the folder, then change the
> request to FolderExists, instead. However, I don't think that's what
> you want either, because if it were the absence of the folder you were
> checking, the next step when it returned False would be to create the
> folder - which you are not doing.
>
> So, which is it? File or folder?
>
> If it's the absence of the folder that it to trigger the action, then
> try this ...
>
> path=CreateObject("WScript.Shell")_
> .ExpandEnvironmentStrings("%UserProfile%") _
> & "\Application Data\Microsoft\Templates")
> dim objFSO
> set objFSO=CreateObject("Scripting.FileSystemObject")
> If objFSO.FolderExists(path) = False Then
> objFSO.CreateFolder path
> objFSO.CopyFile "\\servername\stdapps\custemp\*.docx", path & "\"
> End If
>
> Tom Lavedas
> ===========
> http://members.cox.net/tglbatch/wsh/
>

OK I have made some adjustments that you have suggested. What I want it to
do is scan this folder and see if three files exhist and if they don't copy
these files into this folder. So I have changed the code to look in this
location for the time being one of the three files. If it doesn't exhist
then copy the correct file there. Here is the code I have now.

Option Explicit
dim path
path=CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%\Application Data\Microsoft\Templates\")
dim objFSO
set objFSO=CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(path"\envelope.dotx") = False Then
objFSO.CopyFile "\\servername\stdapps\custemp\envelope.docx", path & "\"
End If


I am now receiving the following error:
Expected ')'
Line 6
char 26
Code 800A03EE.

Thanks again for all your help.


RE: Copy file from server share to user profile by LordDarkHelmet

LordDarkHelmet
Thu Jul 03 10:54:01 CDT 2008

>Lord Dark Helmet" wrote:

> I am attempting to copy some custom Office Templates into user profiles when
> they log on to the computer. I want it to look to see if the files exist and
> if they don't then copy the files from a network share. Here is the Code I
> have come up with.
>
> path=CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%\Application Data\Microsoft\Templates\")
> dim objFSO
> set objFSO=CreateObject("Scripting.FileSystemObject")
> If objFSO.FileExists("path") = False Then
> objFSO.CopyFile "\\servername\stdapps\custemp\*.docx", path
> End If
>
> I am getting an error file not found on line 5 character 1 code 800A0035.
> I've checked and templates are there. Any ideas?
>
> Any Help would be greatly appreciated
>
>
>


OK Got it. Again thanks for your help. I had to do a couple adjustments.
Here is the final code for anybody that would like it. Thanks for your help

Option Explicit
dim path
path=CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%")
& ("\Application Data\Microsoft\Templates")
dim objFSO
set objFSO=CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(path & ("\envelope.dotx")) = False Then
objFSO.CopyFile "\\servername\stdapps\custemp\envelope.dotx", path & "\"
End If
If objFSO.FileExists(path & ("\AgencyFaxCover.dotx"))= False Then
objFSO.CopyFile "\\servername\stdapps\custemp\AgencyFaxCover.dotx", path & "\"
End If
If objFSO.FileExists(path & ("\AgencyLetterhead_BW.dotx"))= False Then
objFSO.CopyFile "\\servername\stdapps\custemp\AgencyLetterhead_BW.dotx",
path & "\"
End If

Re: Copy file from server share to user profile by Pegasus

Pegasus
Thu Jul 03 11:14:17 CDT 2008


"Lord Dark Helmet" <LordDarkHelmet@discussions.microsoft.com> wrote in
message news:83EF02D7-5E87-44A7-9DC6-CA23BFAC5039@microsoft.com...
> "Tom Lavedas" wrote:
>
>> On Jul 2, 3:43 pm, Lord Dark Helmet
>> <LordDarkHel...@discussions.microsoft.com> wrote:
>> > I am attempting to copy some custom Office Templates into user profiles
>> > when
>> > they log on to the computer. I want it to look to see if the files
>> > exist and
>> > if they don't then copy the files from a network share. Here is the
>> > Code I
>> > have come up with.
>> >
>> > path=CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%\Application
>> > Data\Microsoft\Templates\")
>> > dim objFSO
>> > set objFSO=CreateObject("Scripting.FileSystemObject")
>> > If objFSO.FileExists("path") = False Then
>> > objFSO.CopyFile "\\servername\stdapps\custemp\*.docx", path
>> > End If
>> >
>> > I am getting an error file not found on line 5 character 1 code
>> > 800A0035.
>> > I've checked and templates are there. Any ideas?
>> >
>> > Any Help would be greatly appreciated
>>
>> First, take the quotes from around the variable's name in line five.
>> With the quotes, you are passing the literal string, path, to the
>> FileExists method.
>>
>> Once you fix that, a second problem will arise; specifically, you are
>> passing a folder's path to a function that can only test for a file.
>> If you want to test for the presence of the folder, then change the
>> request to FolderExists, instead. However, I don't think that's what
>> you want either, because if it were the absence of the folder you were
>> checking, the next step when it returned False would be to create the
>> folder - which you are not doing.
>>
>> So, which is it? File or folder?
>>
>> If it's the absence of the folder that it to trigger the action, then
>> try this ...
>>
>> path=CreateObject("WScript.Shell")_
>> .ExpandEnvironmentStrings("%UserProfile%") _
>> & "\Application Data\Microsoft\Templates")
>> dim objFSO
>> set objFSO=CreateObject("Scripting.FileSystemObject")
>> If objFSO.FolderExists(path) = False Then
>> objFSO.CreateFolder path
>> objFSO.CopyFile "\\servername\stdapps\custemp\*.docx", path & "\"
>> End If
>>
>> Tom Lavedas
>> ===========
>> http://members.cox.net/tglbatch/wsh/
>>
>
> OK I have made some adjustments that you have suggested. What I want it
> to
> do is scan this folder and see if three files exhist and if they don't
> copy
> these files into this folder. So I have changed the code to look in this
> location for the time being one of the three files. If it doesn't exhist
> then copy the correct file there. Here is the code I have now.
>
> Option Explicit
> dim path
> path=CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%\Application
> Data\Microsoft\Templates\")
> dim objFSO
> set objFSO=CreateObject("Scripting.FileSystemObject")
> If objFSO.FileExists(path"\envelope.dotx") = False Then
> objFSO.CopyFile "\\servername\stdapps\custemp\envelope.docx", path & "\"
> End If
>
>
> I am now receiving the following error:
> Expected ')'
> Line 6
> char 26
> Code 800A03EE.
>
> Thanks again for all your help.
>

In the line

If objFSO.FileExists(path"\envelope.dotx") = False Then

you're trying to concatenate the variable 'path' with the string
'\envelope.dotx'. This is fine for batch files but not so fine for
VB Scripts. To concatenate strings in VB Scripts, use the &
operator:

If objFSO.FileExists(path & "envelope.dotx") = False Then

Note also that you have one backslash too many. If 'path' ends
on a backslash then you must not start '\envelope.dotx' with
a backslash. The same goes for Line 7.