Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default trying to find random drive letters

hi i am tryting to save a file on a sharded drive how ever as other people
will be using it and they have different dirve letters is there a way I can
find what their dirve letter is and then specify what the drive letter is in
my code??
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default trying to find random drive letters

VBAfunkymonk wrote:
hi i am tryting to save a file on a sharded drive how ever as other
people will be using it and they have different dirve letters is
there a way I can find what their dirve letter is and then specify
what the drive letter is in my code??


Use the UNC path. If you need to convert, this function will do it:

' API call used for UNCDOSUNC conversions...
Private Declare Function WNetGetConnectionA Lib "MPR.DLL" (ByVal _
LocalName As String, ByVal RemoteName As String, _
RetLength As Long) As Long
Function UNCPathToDOSPath(UNCName As String) As String
'================================================= ==================
'= Procedu UNCPathToDOSPath =
'= Type: Function =
'= =
'= Purpose: Converts a UNC (Servername\Drive name) path into a =
'= DOS (drive letter) path. =
'= Parameters: UNCName - String - The UNC path/name to convert. =
'= Returns: String - The converted DOS name. An empty string =
'= if the UNC path was not available. =
'= =
'= Version: Date: Developer: Action: =
'=---------|---------|---------------|-----------------------------=
'= 1.0.0 |28-Aug-01| Robert Bruce | Created =
'================================================= ==================

Dim lngMaxLen As Long
Dim strLocalName As String
Dim strRemoteName As String
Dim lngCount As Long
Dim lngGetConRet As Long

' Did we get a DOS rather than a UNC path?..
If Left(UNCName, 2) Like "?:" Then
UNCPathToDOSPath = UNCName
Else

'Loop through drive letters D to Z...
For lngCount = 68 To 90

' Max length of file path...
lngMaxLen = 8192

' Seed drive letter...
strLocalName = Chr(lngCount) & ":"

' Create Buffer for remote name...
strRemoteName = Space(lngMaxLen)

' Feed drive letter into API function
lngGetConRet = WNetGetConnectionA(strLocalName, strRemoteName, _
lngMaxLen)

' API call returns Zero on success...
If lngGetConRet = 0 Then
' Double-check return string - should NOT be just
' a null char...
If InStr(1, strRemoteName, vbNullChar) 1 Then
' Get the portion of the return string up to
' the null character...
strRemoteName = Left(strRemoteName, InStr(1, _
strRemoteName, vbNullChar) - 1)
' Quick test to see of the remote name of the drive
' is longer than our UNC string - no need to carry
' on
' if it is...
If Len(UNCName) Len(strRemoteName) Then
' Check to see if the UNC name begins with the
' remote name of the drive we found...
If Left(UCase(UNCName), Len(strRemoteName)) = _
UCase(strRemoteName) Then
' Strip the remote name off the UNC Name...
strRemoteName = Right(UNCName, _
Len(UNCName) - Len(strRemoteName))
' ...and add the drive letter...
strRemoteName = strLocalName & strRemoteName
' Return the finished string...
UNCPathToDOSPath = strRemoteName
' No need to continue processing...
Exit For
End If
End If
End If
End If
Next

' If no matching UNC Path found then return empty string
If lngCount = 91 Then UNCPathToDOSPath = ""

End If
End Function

--
Rob

Please keep conversations in the newsgroup so that all may contribute
and benefit.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default trying to find random drive letters

Which particular drive letter?

If it is the one to which they save their files by default, use:
Left(application.defaultfilepath,3)

If it is where Excel is installed, use:
Left(application.path,3)


"VBAfunkymonk" wrote:

hi i am tryting to save a file on a sharded drive how ever as other people
will be using it and they have different dirve letters is there a way I can
find what their dirve letter is and then specify what the drive letter is in
my code??

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
letters drive a numeric result mblush Excel Worksheet Functions 3 February 23rd 07 07:05 PM
using network paths rather than drive letters in microsoft query samwardill Excel Discussion (Misc queries) 2 March 8th 06 01:10 PM
How do I find random number in list of random alpha? (Position is. jlahealth-partners Excel Discussion (Misc queries) 0 February 8th 05 05:31 PM
Reflect file path (show drive letters) in Excel 2000 Alicia Excel Discussion (Misc queries) 4 January 20th 05 06:49 PM
Find links with code; change from G drive to C drive Sandy[_3_] Excel Programming 4 July 26th 03 07:24 PM


All times are GMT +1. The time now is 12:33 AM.

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

About Us

"It's about Microsoft Excel"