Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    FileCopy (Word XP)

    Using VBA, I want to copy a file on the local drive to another location. I can't seem to get the code right. I've added MS Scriptin Runtime as a Reference, but I'm having trouble setting the object before copying the file.

    I'm not sure what it is that I need to set as the object. The Help File isn't making sense to me....

    fso.CopyFile source, destination

    What is fso???

    Thanks,
    Richard Barrett

  2. #2
    5 Star Lounger
    Join Date
    Oct 2002
    Location
    Wellington, Wellington, New Zealand
    Posts
    621
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileCopy (Word XP)

    Richard

    fso will probably be FileSystemObject which is declared and assigned as the result of a set statement.
    I've included a piece of code that deals with these - it may give you some clues as to how to set one even though it has little to do with your example <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Sub TitlesList()
    ' This is a generic routine to obtain a set of files and then generate a document
    ' containing Hyperlinks to that set
    ' Designed so that simplistic tests of 'properties to filter' can select
    ' Documents with particular attributes
    '
    Dim FS As Variant
    Dim FO As Variant
    Dim FL As Variant

    Dim ListString As String
    Dim ListStringURL As String
    Dim I As Long
    Dim IMax As Long
    Dim MyTemp As String
    Dim MyDoc As String
    Dim MyPath As String
    Dim DocMustBeOpened As Boolean
    Dim DocWanted As Boolean


    MyPath = Application.Options.DefaultFilePath(wdDocumentsPat h)
    If Documents.Count > 1 Then
    If ActiveDocument.Path <> "" Then
    MyPath = ActiveDocument.Path
    End If
    End If

    ChangeFileOpenDirectory MyPath

    Set FS = CreateObject("Scripting.FileSystemObject")
    Set FO = FS.getfolder(MyPath)

    Documents.Add
    MyDoc = ActiveDocument.Name
    DocMustBeOpened = True

    For Each FL In FO.Files
    MyTemp = FL.Name
    If Right(MyTemp, 4) = ".doc" Then
    DocWanted = True
    If DocMustBeOpened Then
    Documents.Open Filename:=MyTemp, ReadOnly:=True, _
    AddToRecentFiles:=False
    If ActiveDocument.Comments.Count = 0 Then
    DocWanted = False
    End If
    ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
    End If
    Else
    DocWanted = False
    End If
    If DocWanted Then
    Documents(MyDoc).Hyperlinks.Add Anchor:=Selection.Range, Address:= _
    MyPath & "" & MyTemp, SubAddress:=""
    Documents(MyDoc).Paragraphs.Add
    Selection.MoveDown Unit:=wdParagraph
    End If
    Next
    Set FS = Nothing
    Set FO = Nothing
    End Sub

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: FileCopy (Word XP)

    Thanks for the quick answer. What I was missing was:
    Set FS = CreateObject("Scripting.FileSystemObject")

    Richard

Posting Permissions

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