FileSystemObject.copyfile

P

Phil Stokes

I have been trying to copy a file using the following code but it gives the
error

Error '438'

Object doesn't support this property or method

Code below


Dim UpdateTimeElement(0 To 3) As String
Dim Network_path, local_path
Public Sub main() '(UpdateTimeElement)

Call GetNetworkPath.main(Network_path, local_path)
Dim FileNameArray As Variant
Dim ProdNumArray As Variant
Dim outMessage As String
Dim oOutlook As New outlook.Application
Dim oMessage As outlook.MailItem
Dim FileNumber As Integer
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")



FileNameArray = Array("0021", "0003", "0017", "0045")

Set oMessage = oOutlook.CreateItem(olMailItem)
With oMessage
.To = some email address
.Subject = Format(Now(), "hhmm ddd, dd-mmm-yyyy")
For i = 0 To 3
Set fs = Application.FileSearch
With fs
.LookIn = "z:\" + FileNameArray(i) + "\"
.filename = "z:\" + FileNameArray(i) + "\" +
FileNameArray(i) + ".1"
If .Execute(SortBy:=msoSortByFileName,
SortOrder:=msoSortOrderAscending) > 0 Then
filename = "z:\" + FileNameArray(i) + "\" +
FileNameArray(i) + ".1"

fs.CopyFile filename, "c:\temp"
Else
filename = "z:\" + FileNameArray(i) + "\" +
FileNameArray(i) + ".2"
End If
End With
.Attachments.Add filename, olByValue, 1, FileNameArray(i) +
".tif"
Next i
.body = outMessage
.Display
End With
End Sub




I dont know if i'm just not understning how to use this FleSystemObject
initially I just had

FileSystemObject.CopyFile "c:\mydocuments\letters\*.doc", "c:\tempfolder\"
in the code but it didn't work either. should I declare someting for this
to work.

I think i really need some help

Phil
 
P

Phil Stokes

I am sorry if anyone spent any time on the problem below. I have sorted out
the many mistakes in the code below and managed to get it working as I
wanted. The minute it was posted I began to see the mistakes one by one.

Phil
 
A

Alex

Hi Phil,

Phil Stokes said:
I am sorry if anyone spent any time on the problem below. I have sorted out
the many mistakes in the code below and managed to get it working as I
wanted. The minute it was posted I began to see the mistakes one by one.

It is customary to post the solution that you found, for other people to learn from.


Best wishes,
Alex.
 
P

Phil Stokes

This works

TPublic Sub main()

Dim FileNameArray As Variant
Dim ProdNumArray As Variant
Dim outMessage As String
Dim oOutlook As New outlook.Application
Dim oMessage As outlook.MailItem
Dim FileNumber As Integer
Dim fso
Dim fs
Dim filname(3) As String

'On Error Resume Next

'FileSystemObject.CopyFile "c:\mydocuments\letters\*.doc", "c:\tempfolder\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fs = CreateObject("Scripting.FileSystemObject")

FileNameArray = Array("0003", "0017", "0045")

For i = 0 To UBound(FileNameArray, 1)
Set fs = Application.FileSearch
With fs
.LookIn = "z:\" + FileNameArray(i) + "\"
.filename = "z:\" + FileNameArray(i) + "\" +
FileNameArray(i) + ".1"
If .Execute(SortBy:=msoSortByFileName,
SortOrder:=msoSortOrderAscending) > 0 Then
filname(i) = "z:\" + FileNameArray(i) + "\" +
FileNameArray(i) + ".1"
Else
filname(i) = "z:\" + FileNameArray(i) + "\" +
FileNameArray(i) + ".2"
End If
End With
Next i
For i = 0 To UBound(FileNameArray, 1)
fso.CopyFile filname(i), "c:\temp\" + FileNameArray(i) +
".tif"
Next i


Set oMessage = oOutlook.CreateItem(olMailItem)
With oMessage
.To = "some recipient"
.Subject = "some subject"
For i = 0 To UBound(FileNameArray, 1)
.Attachments.Add "c:\temp\" + FileNameArray(i) + ".tif",
olByValue, 1, FileNameArray(i) + ".tif"
Next i
.body = outMessage
.Display
End With
Set fs = Nothing
Set fso = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top