Question How to copy an excel file with vb

pokajy

New member
Joined
Jul 5, 2010
Messages
3
Programming Experience
Beginner
Hello

I need some help.

I've an excel file D:\excel1.xls

Now date is : July2010
Now time is: 1229 (12:29)

When a = 1,
I want my vb program to check the actual date. if there is not a folder D:\July2010 program firstly creat a folder.

And vb program will copy excel1.xls file and paste it into July2010 folder by chaning the file name as Excel1_1229.xls

How can I do that ?

thank you very much
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,465
Location
Norway
Programming Experience
10+
VB.NET:
Dim now As Date = Date.Now
Dim month As String = now.ToString("MMMMyyyy")
Dim timePath As String = String.Format("D:\{0}\excel1_{1}.xls", month, now.ToString("HHmm"))
Try
    My.Computer.FileSystem.CopyFile("D:\excel1.xls", timePath, True)
Catch ex As Exception
    Debug.WriteLine(ex.Message)
End Try
CopyFile method creates the directory if it doesn't exist.
 

pokajy

New member
Joined
Jul 5, 2010
Messages
3
Programming Experience
Beginner
Thank you very much.

But I've still a problem. I think I'm in wrong place because I'm not making a project on visual studio.net
I need vb code.. not vb.net code.
So this code is not working on my project :(

I tried like this.Firstly I just tried to copy file. But it's still not working

Function Width_Trigger(Byval Item)
Dim start
start = HMIRuntime.Tags.Item ("STARTINGBOOL").Read
If start=1 Then
My.Computer.FileSystem.CopyFile "D:\excel1.xls", "d:\excel2.xls"
HMIRuntime.Tags.Item ("STARTINGBOOL").Write False
End If
End Function



I also tried My.Computer.FileSystem.CopyFile ( "D:\excel1.xls", "d:\excel2.xls" ) and

My.Computer.FileSystem.CopyFile ( "D:\excel1.xls", "d:\excel2.xls" , true )
 
Top Bottom