Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default ChDir - Specify Folder

I've tried two variations trying to specify the folder for GetOpenFilename.
The first defaults to the directory last used, the second gives me an error
message of "Invalid procedure call or argument". I can't use ChDrive "I"
because the letter is different for each of my users. Any suggestions?

Sub OpenPlacements()

ChDir "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery MIS\Placements"

Filename = Application.GetOpenFilename("Excel Files (*.xls),*.xls)", , _
"Please choose a Placement file to open", True)

End Sub

Sub Openplacements2()

Dim FileToOpen As Variant
Dim MyPath As String
Dim Wb As Workbook

MyPath = "\\Fl-aejf-fs1\Data\Data\EXLDATA\Loan Recovery MIS\Placements"
ChDrive "\\Fl-aejf-fs1\Data\Data"
ChDir MyPath

FileToOpen = Application.GetOpenFilename("Excel Files (*.xls), *.xls", , _
"Please choose a Placement file to open", , True)

If FileToOpen < False Then
Set Wb = Workbooks.Open(FileToOpen)
Else
Exit Sub
End If

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default ChDir - Specify Folder

Previously posted by Rob Bovey:
' Placed at the top of a general module outside any procedures:
Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long

Sub ChDirNet(szPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)
If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting path."
End Sub

' sample usage

Sub FindFile()
ChDirNet "\\LOGD0FILES\OGILVTW\Docs\Temp"
fName = Application.GetOpenFileName
End Sub

--
Regards,
Tom Ogilvy

"StephanieH" wrote in message
...
I've tried two variations trying to specify the folder for

GetOpenFilename.
The first defaults to the directory last used, the second gives me an

error
message of "Invalid procedure call or argument". I can't use ChDrive "I"
because the letter is different for each of my users. Any suggestions?

Sub OpenPlacements()

ChDir "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery

MIS\Placements"

Filename = Application.GetOpenFilename("Excel Files (*.xls),*.xls)", , _
"Please choose a Placement file to open", True)

End Sub

Sub Openplacements2()

Dim FileToOpen As Variant
Dim MyPath As String
Dim Wb As Workbook

MyPath = "\\Fl-aejf-fs1\Data\Data\EXLDATA\Loan Recovery

MIS\Placements"
ChDrive "\\Fl-aejf-fs1\Data\Data"
ChDir MyPath

FileToOpen = Application.GetOpenFilename("Excel Files (*.xls), *.xls",

, _
"Please choose a Placement file to open", , True)

If FileToOpen < False Then
Set Wb = Workbooks.Open(FileToOpen)
Else
Exit Sub
End If

End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default ChDir - Specify Folder

I took Ron's entry and adjusted to inlude our file path. It highlights
"SetCurrentDirectoryA" and gives me an error reading "Sub or Function not
defined"..
Here's what I have
Sub ChDirNet(szPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)
If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting path."
End Sub


Sub FindFile()
Dim FName As Variant

ChDirNet "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery
MIS\Placements"
FName = Application.GetOpenFilename
End Su



"StephanieH" wrote:

I've tried two variations trying to specify the folder for GetOpenFilename.
The first defaults to the directory last used, the second gives me an error
message of "Invalid procedure call or argument". I can't use ChDrive "I"
because the letter is different for each of my users. Any suggestions?

Sub OpenPlacements()

ChDir "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery MIS\Placements"

Filename = Application.GetOpenFilename("Excel Files (*.xls),*.xls)", , _
"Please choose a Placement file to open", True)

End Sub

Sub Openplacements2()

Dim FileToOpen As Variant
Dim MyPath As String
Dim Wb As Workbook

MyPath = "\\Fl-aejf-fs1\Data\Data\EXLDATA\Loan Recovery MIS\Placements"
ChDrive "\\Fl-aejf-fs1\Data\Data"
ChDir MyPath

FileToOpen = Application.GetOpenFilename("Excel Files (*.xls), *.xls", , _
"Please choose a Placement file to open", , True)

If FileToOpen < False Then
Set Wb = Workbooks.Open(FileToOpen)
Else
Exit Sub
End If

End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default ChDir - Specify Folder

This line:

Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long

shouldn't be changed and has to be kept at the top of your module. It's the API
Function that makes it work. Just leave it as-is.



StephanieH wrote:

I took Ron's entry and adjusted to inlude our file path. It highlights
"SetCurrentDirectoryA" and gives me an error reading "Sub or Function not
defined"..
Here's what I have
Sub ChDirNet(szPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)
If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting path."
End Sub

Sub FindFile()
Dim FName As Variant

ChDirNet "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery
MIS\Placements"
FName = Application.GetOpenFilename
End Su

"StephanieH" wrote:

I've tried two variations trying to specify the folder for GetOpenFilename.
The first defaults to the directory last used, the second gives me an error
message of "Invalid procedure call or argument". I can't use ChDrive "I"
because the letter is different for each of my users. Any suggestions?

Sub OpenPlacements()

ChDir "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery MIS\Placements"

Filename = Application.GetOpenFilename("Excel Files (*.xls),*.xls)", , _
"Please choose a Placement file to open", True)

End Sub

Sub Openplacements2()

Dim FileToOpen As Variant
Dim MyPath As String
Dim Wb As Workbook

MyPath = "\\Fl-aejf-fs1\Data\Data\EXLDATA\Loan Recovery MIS\Placements"
ChDrive "\\Fl-aejf-fs1\Data\Data"
ChDir MyPath

FileToOpen = Application.GetOpenFilename("Excel Files (*.xls), *.xls", , _
"Please choose a Placement file to open", , True)

If FileToOpen < False Then
Set Wb = Workbooks.Open(FileToOpen)
Else
Exit Sub
End If

End Sub



--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default ChDir - Specify Folder

Works perfectly. Sorry, I thought the Kernel32 was was where I put my
pathname..

Thanks!



"Dave Peterson" wrote:

This line:

Private Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long

shouldn't be changed and has to be kept at the top of your module. It's the API
Function that makes it work. Just leave it as-is.



StephanieH wrote:

I took Ron's entry and adjusted to inlude our file path. It highlights
"SetCurrentDirectoryA" and gives me an error reading "Sub or Function not
defined"..
Here's what I have
Sub ChDirNet(szPath As String)
Dim lReturn As Long
lReturn = SetCurrentDirectoryA(szPath)
If lReturn = 0 Then Err.Raise vbObjectError + 1, "Error setting path."
End Sub

Sub FindFile()
Dim FName As Variant

ChDirNet "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery
MIS\Placements"
FName = Application.GetOpenFilename
End Su

"StephanieH" wrote:

I've tried two variations trying to specify the folder for GetOpenFilename.
The first defaults to the directory last used, the second gives me an error
message of "Invalid procedure call or argument". I can't use ChDrive "I"
because the letter is different for each of my users. Any suggestions?

Sub OpenPlacements()

ChDir "\\Fl-aejf-fs1\Data\Data\RECOVERY\EXLDATA\Loan Recovery MIS\Placements"

Filename = Application.GetOpenFilename("Excel Files (*.xls),*.xls)", , _
"Please choose a Placement file to open", True)

End Sub

Sub Openplacements2()

Dim FileToOpen As Variant
Dim MyPath As String
Dim Wb As Workbook

MyPath = "\\Fl-aejf-fs1\Data\Data\EXLDATA\Loan Recovery MIS\Placements"
ChDrive "\\Fl-aejf-fs1\Data\Data"
ChDir MyPath

FileToOpen = Application.GetOpenFilename("Excel Files (*.xls), *.xls", , _
"Please choose a Placement file to open", , True)

If FileToOpen < False Then
Set Wb = Workbooks.Open(FileToOpen)
Else
Exit Sub
End If

End Sub



--

Dave Peterson

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
Problems with ChDrive, ChDir Sophie Excel Programming 4 November 29th 04 09:35 AM
ChDir Error scain2004[_23_] Excel Programming 1 November 4th 04 08:08 PM
chdir not accepting string for path Alan Excel Programming 1 October 13th 04 06:18 PM
Links and Chdir Hansol Excel Programming 3 April 17th 04 08:52 PM
application.dialogs(xlDialogSaveAs) AND CHDIR Jules[_2_] Excel Programming 1 September 3rd 03 08:27 PM


All times are GMT +1. The time now is 08:25 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"