Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving Files into an archive Sher Excel Discussion (Misc queries) 2 October 3rd 07 01:06 PM
Moving files which are linked chrismc1972 Excel Discussion (Misc queries) 1 January 23rd 07 09:28 PM
Moving xls files that have links?? Bill Links and Linking in Excel 2 November 2nd 06 06:57 AM
Moving files in Netscape B. Jensen Excel Programming 0 August 14th 05 01:56 PM
Moving Files in Excel D Huber Excel Discussion (Misc queries) 1 June 24th 05 08:00 PM


All times are GMT +1. The time now is 02:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"