0% found this document useful (0 votes)
42 views

Copy1 - VBA Made Simple

This document provides code examples for performing common file and folder operations in Visual Basic for Applications (VBA), including opening a folder, creating and deleting folders, renaming folders, checking for a file/folder existence, getting a file's modification date and time, and opening a website.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Copy1 - VBA Made Simple

This document provides code examples for performing common file and folder operations in Visual Basic for Applications (VBA), including opening a folder, creating and deleting folders, renaming folders, checking for a file/folder existence, getting a file's modification date and time, and opening a website.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 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

You might also like