Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Creating a directory from within Excel VBA
Hi all,
I'm creating a little VBA script within Ms Excel, wanting the script to change directory before writing a file, using the ChangeFileOpenDirectory method. It works fine. But what if the directory does not exist? Then I want the script to create it. Can you please tell me how I make it do so? Thank you very much in advance. Jo |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Creating a directory from within Excel VBA
One way
Sub stantial() On Error GoTo ErrNotExist ChDir ("C:\Mydir") Exit Sub ErrNotExist: MkDir "c:\Mydir" End Sub Mike "Jo Gjessing" wrote: Hi all, I'm creating a little VBA script within Ms Excel, wanting the script to change directory before writing a file, using the ChangeFileOpenDirectory method. It works fine. But what if the directory does not exist? Then I want the script to create it. Can you please tell me how I make it do so? Thank you very much in advance. Jo |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Creating a directory from within Excel VBA
You could also try this
Sub selectfolder() Dim objShell As Object, objFolder As Object Set objShell = CreateObject("Shell.Application") On Error Resume Next Set objFolder = objShell.BrowseForFolder(&H0&, "Select Folder ", &H1&) If Not objFolder Is Nothing Then Set oFolderItem = objFolder.Items.Item MyPath = oFolderItem.Path ChDir (MyPath) End If End Sub "Mike H" wrote: One way Sub stantial() On Error GoTo ErrNotExist ChDir ("C:\Mydir") Exit Sub ErrNotExist: MkDir "c:\Mydir" End Sub Mike "Jo Gjessing" wrote: Hi all, I'm creating a little VBA script within Ms Excel, wanting the script to change directory before writing a file, using the ChangeFileOpenDirectory method. It works fine. But what if the directory does not exist? Then I want the script to create it. Can you please tell me how I make it do so? Thank you very much in advance. Jo |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
creating directory for workbook | Excel Discussion (Misc queries) | |||
Creating an excel macro to open and save sheets to a different directory | Excel Programming | |||
Creating a macro that lists directory names within a directory.... | Excel Programming | |||
saving/creating a directory | Excel Programming | |||
Creating a directory from a date | Excel Programming |