View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Dana DeLouis[_3_] Dana DeLouis[_3_] is offline
external usenet poster
 
Posts: 690
Default How to find the drive letter?

Not sure if this will work for you, so I'll just throw it out.

Sub Demo()
' Dana DeLouis
Dim Remember As String
Dim FullFileName As String

Remember = CurDir$
FullFileName = ActiveWorkbook.FullName

'// This is ok
ChDrive FullFileName
ChDir "\Finance\TLPtimesheet\CSVFiles"

' Do your stuff he

'If you want to go back...
ChDrive Remember
ChDir Remember
End Sub

--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"Mervyn Thomas" wrote in message
...
Just to complete the subject this is what I now use and works fine on any
hard drive:
As a little niggle - I don't understand the need for all these double

quotes
and "&"'s but VB is a bit pedantic!!

'find path letter and change directory to CSVFiles
Dim readFullPath As String 'of this workbook
Dim readDriveLetter As String
Dim NewFullPath As String
readFullPath = ActiveWorkbook.FullName
readDriveLetter = Left(readFullPath, 1)
NewFullPath = readDriveLetter &
":\Finance\TLPtimesheet\CSVFiles"
ChDir "" & NewFullPath & ""
Mervyn

"Tom Ogilvy" wrote in message
...
That doesn't seem to work unless the string (path) already has the drive
letter in it. Can you elaborate on your solution with respect to the
question of the original poster?

From what I can see

fso.GetDriveName(pstrPath)

alone would return the drive letter, but it looks to be little more than

a
string parsing function (although it will parse a UNC path).

--
Regards,
Tom Ogilvy

"tolgag " wrote in message
...
Hi,

With help of FileSystemObject you can get the driveletter of a path,
like this :

Function readDriveLetter(pstrPath as String) as String

Dim fso, d
Set fso = CreateObject("Scripting.FileSystemObject")
Set d = fso.GetDrive(fso.GetDriveName(pstrPath))
readDriveLetter = d

End Function


---
Message posted from http://www.ExcelForum.com/