View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Varun Varun is offline
external usenet poster
 
Posts: 37
Default How to change directory

Folks,

VBA newbie here...I am unable to "change directory" to a folder name that (I
think) is (already) being returned to me via the Sub (I think I need a
function in order to do this but not sure).

The code is below. The main program right below calls out 2 subs and 1
function. What I need to do is chdir to a folder that is returned to me by
the Sub GetMentDesContPath. Do I need to change the Sub to Function in order
to accomplish this?

The program errors out at ChDir MentorDirectory

Thanks,
Varun




Private Sub CommandMAINBUTTON_Click()

Call GetMentDesContPath
MentorDirectory = MentDesContPath

'Check to see if GEOMS ASCII and error out if it does not geoms_ascii
'Check to see if design container has /pcb subdir

If PathExists(MentDesCont & "pcb") = False Then
MsgBox "Invalid Mentor Design container specified, exiting"
Exit Sub
Else
ChDir MentorDirectory

If FileExists(MentDesCont, geoms_ascii) = False Then
MsgBox "Couldn't find geoms_ascii file, exiting"
Exit Sub
Else
'open geoms_ascii file

End If

End If

End Sub


Sub GetMentDesContPath()
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = "My Computer"
.Title = "Please navigate to the Mentor Design Container"
.Show
If .SelectedItems.Count < 0 Then
MentDesCont = .SelectedItems(1)
End If
End With
End Sub



Function PathExists(pname) As Boolean
' returns true if the path exists
On Error Resume Next
PathExists = (GetAttr(pname) And vbDirectory) = vbDirectory
End Function



Function FileExists(path, fname) As Boolean
With Application.FileSearch
.NewSearch
.Filename = fname
.LookIn = MentDesCont
.Execute
If .FoundFiles.Count = 1 Then
FileExists = True
Else
FileExists = False
End If
End With
End Function