Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default How to change directory

You are assigning values to local variables, which have no value when you
reference them from other procedures. You refer to MentDesContPath but have
never assigned a value to it. You assign a value to MentDesCont in the
GetMentDesContPath procedure, but it ceases to exist when that sub ends. The
MentDesCont you refer to elsewhere is a different variable. The following
works for me if I have assigned a value to geoms_ascii:

Option Explicit
Dim MentDesContPath As String

Private Sub CommandMAINBUTTON_Click()
Call GetMentDesContPath
'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(MentDesContPath & "pcb") = False Then
MsgBox "Invalid Mentor Design container specified, exiting"
Exit Sub
Else
ChDir MentDesContPath
If FileExists(MentDesContPath, 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

Private Sub GetMentDesContPath()
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = "My Computer"
.Title = "Please navigate to the Mentor Design Container"
.Show
If .SelectedItems.Count < 0 Then
MentDesContPath = .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 = MentDesContPath
.Execute
If .FoundFiles.Count = 1 Then
FileExists = True
Else
FileExists = False
End If
End With
End Function

Hope this helps,

Hutch

"Varun" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default How to change directory

Thanks Tom. Yeah, I had multiple errors there.

Modifying per your suggestions works now.

Thanks again.

"Tom Hutchins" wrote:

You are assigning values to local variables, which have no value when you
reference them from other procedures. You refer to MentDesContPath but have
never assigned a value to it. You assign a value to MentDesCont in the
GetMentDesContPath procedure, but it ceases to exist when that sub ends. The
MentDesCont you refer to elsewhere is a different variable. The following
works for me if I have assigned a value to geoms_ascii:

Option Explicit
Dim MentDesContPath As String

Private Sub CommandMAINBUTTON_Click()
Call GetMentDesContPath
'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(MentDesContPath & "pcb") = False Then
MsgBox "Invalid Mentor Design container specified, exiting"
Exit Sub
Else
ChDir MentDesContPath
If FileExists(MentDesContPath, 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

Private Sub GetMentDesContPath()
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = "My Computer"
.Title = "Please navigate to the Mentor Design Container"
.Show
If .SelectedItems.Count < 0 Then
MentDesContPath = .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 = MentDesContPath
.Execute
If .FoundFiles.Count = 1 Then
FileExists = True
Else
FileExists = False
End If
End With
End Function

Hope this helps,

Hutch

"Varun" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Directory Compass Rose Excel Programming 1 July 30th 07 03:35 PM
Change current directory to the directory that the workbook loads from! alondon Excel Programming 5 April 17th 07 06:05 AM
Change directory Jeff Excel Discussion (Misc queries) 6 September 27th 06 04:08 PM
Change Directory Help! smonczka Excel Programming 3 August 19th 05 05:55 PM
Change directory for DOS window Garry[_4_] Excel Programming 1 January 9th 04 05:44 PM


All times are GMT +1. The time now is 05:31 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"