Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Copy files from a server to C: (Office XP, SP-2)

    Have tried to make a procedure to be able to copy files from a server to local machine.

    Have tried this code:

    <pre>Sub CopyTemplatesToLocalmashine()

    FileSystemObject.CopyFile "corp.4tel.noGlobaldataInfoBEETemplUnderDevWor d _
    Startup*.dot", "C:TEMP"
    FileSystemObject.CopyFile "corp.4tel.noGlobaldataInfoBEETemplUnderDevWor d _
    Workgroup-templates*.dot", "C:TEMP_1"

    </pre>

    End Sub

    I guess I need to Dim the path of the source and the path of the destination.
    But I cannot find the correct code.
    None of the files are open.
    They need to replace existing files on the destination.

    Can anyone help?

    Thanks

    Bjorn

  2. #2
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Copy files from a server to C: (Office XP, SP-2)

    Thanks Hans!

    It will be a good help when I want someone else to test my templates without having to disturb the environment for others and not having to logg off and on to get hold of the nw templates.

    I have also tried to use another method:
    WinZip and making a self - extracting file, but then I need to make a new zip-file every time a have a changed a template and it needs to be tested.

    regards
    Bjorn

  3. #3
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Brussels, Brussel, Belgium
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copy files from a server to C: (Office XP, SP-2)

    there's only a small concatenation problem afaics:
    (after edit: need to instantiate the filesystemobject, set a reference to the fso object library)

    Sub CopyTemplatesToLocalmashine()
    dim FSO as new filesystemobject
    FSO .CopyFile _
    "corp.4tel.noGlobaldataInfoBEETemplUnderDevWor d" & _
    "Startup*.dot", "C:TEMP"
    FSO .CopyFile _
    "corp.4tel.noGlobaldataInfoBEETemplUnderDevWor d" & _
    "Workgroup-templates*.dot", "C:TEMP_1"
    End Sub

    alternatively, use the copy console command inside a shell statement, so you don't need a reference - or use late binding (createobject(...)):
    x=shell("copy serversharefiles c:destination")

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Copy files from a server to C: (Office XP, SP-2)

    You need to create an object of type FileSystemObject

    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")

    You can use the CopyFile method of this object; it has a third argument OverWriteFiles that can be set to True or False; the default value is True, so you don't need to specify it in your case.

    Sub CopyTemplatesToLocalMachine()
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.CopyFile "corp.4tel.noGlobaldataInfoBEETemplUnderDevWordSta rtup*.dot", "C:TEMP"
    fso.CopyFile "corp.4tel.noGlobaldataInfoBEETemplUnderDevWordWor kgroup-templates*.dot", "C:TEMP_1"
    Set fso = Nthing
    End Sub

    Edited to correct strings (removed continuation characters) - thanks to <!profile=Pieter>Pieter<!/profile> for pointing it out.

  5. #5
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Copy files from a server to C: (Office XP, SP-2)

    Thanks pieter,
    I have tried but got error message:
    User defined type not defined: "filesystemobject"



    The next method I haven't tried so far. It is a bit unknown to me.

    Regards
    Bjorn

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Copy files from a server to C: (Office XP, SP-2)

    As Pieter mentioned, his code will only work if you set a reference (in Tools | References...) to a library that exposes FileSystemObject, such as Microsoft Scripting Runtime or Windows Script Host. This is called early binding: you set a reference to the correct library, so that VBA knows beforehand what you're going to use. Advantage is that you can see which properties and methods are available.

    The alternative is late binding: you define the object type in runtime; that is what I used in my example:

    Dim fso As Object ' unspecified object type
    Set fso = CreateObject("Scripting.FileSystemObject")

    You don't need a reference for this to work, but you can't see which properties and methods fso has, you'll have to rely on the documentation.

  7. #7
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Copy files from a server to C: (Office XP, SP-2)

    Thanks Hans,

    Now I understand and will look into it later.

    (An amateur should not twine into complicated VBA!)

    I'm extremely thankful for the help you all give!

    Regards
    Bjorn

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •