Sie sind auf Seite 1von 2

Visual Basic for Application Working with files and folder Code to open a folder Sub openfolder() Shell

"explorer.exe " & "folder path", vbNormalFocus End Sub Code to Create a Folder Sub createfolder () MkDir "C:\Users\home\Desktop\test1" End Sub Code to delete a folder Sub createfolder() RmDir "C:\Users\home\Desktop\test1" End Sub Code to rename an existing folder Sub changefoldername() Name "C:\Users\home\Desktop\test" As "C:\Users\home\Desktop\TestTest" End Sub Code to check the existence of a file or folder We need to run the below codes in Immediate window to see the results, they should not start with Sub or End Sub. To go to the immediate window, go to view and immediate window or press ctrl+G ?dir(C:\Users\home\Desktop\TestTest,vbDirectory) then press enter Output will be seen as below ?dir("C:\Users\home\Desktop\TestTest",vbDirectory) TestTest

Code for finding out the date and time when the file was modified This piece of code also should run in the immediate window to see the output ?filedatetime("C:\Users\home\Desktop\TestTest") then press Enter Output in immediate window comes like this ?filedatetime("C:\Users\home\Desktop\TestTest") 6/25/2011 6:53:52 PM Code to open any website
Sub VisitWebsite() Dim ie As Object Set ie = CreateObject("INTERNETEXPLORER.APPLICATION") ie.NAVIGATE "http://websiteaddress" ie.Visible = True While ie.busy DoEvents Wend End Sub