Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Moving files via code
Hello all,
I found this code in a previous post to move files with code: Sub test() MoveAllFiles "P:\new-journals", "P:\processed-journals" End Sub Sub MoveAllFiles(Source As String, Dest As String) Dim objFS As New FileSystemObject Dim objSource As Folder Dim objDest As Folder Dim objFile As File On Error GoTo MoveAllFiles_Err: If objFS.FolderExists(Source) Then If objFS.FolderExists(Dest) Then Set objSource = objFS.GetFolder(Source) Set objDest = objFS.GetFolder(Dest) For Each objFile In objSource.Files objFile.Move (objDest.Path & _ Application.PathSeparator & objFile.Name) Next Else Err.Raise vbObjectError + 1001, "", _ "Folder " & Source & " not found." End If Else Err.Raise vbObjectError + 1001, "", _ "Folder " & Source & " not found." End If Exit Sub MoveAllFiles_Err: With Err .Raise .Number, "[MoveAllFiles]" & .Source, _ .Description, .HelpFile, .HelpContext End With End Sub With this example, I can modify this code to get it to do what I want. The problem that I'm having is that in the line of code: Dim objFS As New FileSystemObject it appears that my system doesn't recognize "FileSystemObject" as a valid data type. Do I need to reference another library for this to work? Any help anyone can provide will be greatly appreciated, Conan Kelly |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Moving files via code
You have to set a reference to the Microsoft Scripting Runtime library in
VBA. In the VBIDE, go to ToolsReferences and set it. -- HTH RP (remove nothere from the email address if mailing direct) "Conan Kelly" <CTBarbarin at msn dot com wrote in message ... Hello all, I found this code in a previous post to move files with code: Sub test() MoveAllFiles "P:\new-journals", "P:\processed-journals" End Sub Sub MoveAllFiles(Source As String, Dest As String) Dim objFS As New FileSystemObject Dim objSource As Folder Dim objDest As Folder Dim objFile As File On Error GoTo MoveAllFiles_Err: If objFS.FolderExists(Source) Then If objFS.FolderExists(Dest) Then Set objSource = objFS.GetFolder(Source) Set objDest = objFS.GetFolder(Dest) For Each objFile In objSource.Files objFile.Move (objDest.Path & _ Application.PathSeparator & objFile.Name) Next Else Err.Raise vbObjectError + 1001, "", _ "Folder " & Source & " not found." End If Else Err.Raise vbObjectError + 1001, "", _ "Folder " & Source & " not found." End If Exit Sub MoveAllFiles_Err: With Err .Raise .Number, "[MoveAllFiles]" & .Source, _ .Description, .HelpFile, .HelpContext End With End Sub With this example, I can modify this code to get it to do what I want. The problem that I'm having is that in the line of code: Dim objFS As New FileSystemObject it appears that my system doesn't recognize "FileSystemObject" as a valid data type. Do I need to reference another library for this to work? Any help anyone can provide will be greatly appreciated, Conan Kelly |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Moving Files into an archive | Excel Discussion (Misc queries) | |||
Moving files which are linked | Excel Discussion (Misc queries) | |||
Moving xls files that have links?? | Links and Linking in Excel | |||
Moving files in Netscape | Excel Programming | |||
Moving Files in Excel | Excel Discussion (Misc queries) |