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

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Copy files from a server to C: (Office XP, SP-2)

    Author
    Topic
    #391555

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

    Have tried this code:

    Sub CopyTemplatesToLocalmashine()
    
            FileSystemObject.CopyFile "corp.4tel.noGlobaldataInfoBEETemplUnderDevWord _
    Startup*.dot", "C:TEMP"
            FileSystemObject.CopyFile "corp.4tel.noGlobaldataInfoBEETemplUnderDevWord _
    Workgroup-templates*.dot", "C:TEMP_1"
    
    

    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

    Viewing 1 reply thread
    Author
    Replies
    • #699795

      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.noGlobaldataInfoBEETemplUnderDevWord” & _
      “Startup*.dot”, “C:TEMP”
      FSO .CopyFile _
      “corp.4tel.noGlobaldataInfoBEETemplUnderDevWord” & _
      “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”)

      • #699817

        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

        • #699827

          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.

          • #699855

            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

    • #699793

      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.noGlobaldataInfoBEETemplUnderDevWordStartup*.dot”, “C:TEMP”
      fso.CopyFile “corp.4tel.noGlobaldataInfoBEETemplUnderDevWordWorkgroup-templates*.dot”, “C:TEMP_1”
      Set fso = Nthing
      End Sub

      Edited to correct strings (removed continuation characters) – thanks to Pieter for pointing it out.

      • #699794

        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

    Viewing 1 reply thread
    Reply To: Copy files from a server to C: (Office XP, SP-2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: