Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default protective measure

I want excel to backup sheet "Record" using code but only onto a Pendrive
when a workbook is close.
The path of any removable drive may change from time to time.
Can excel extract the path names of only removable drives at any one time,
or can i somehow extract an 'identifier' on the pendrive.

Thanks guys and girls, for all your help so for. Tt's been productive.

Sunil


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default protective measure

Uniquely identify your drive with some dummy file in the root folder


Private Declare Function GetDriveType Lib "kernel32" _
Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Const DRIVE_REMOVABLE As Long = 2
'Private Const DRIVE_FIXED = 3
'Private Const DRIVE_REMOTE = 4 ' eg network
'Private Const DRIVE_CDROM = 5
'Private Const DRIVE_RAMDISK = 6

Sub testGetDrive()
Dim sDrive As String
Const cKNOWNFILE As String = "unique_file.txt" ' << change

If GetDrive(sDrive, cKNOWNFILE) Then
MsgBox sDrive
Else
MsgBox "not found"
End If

End Sub

Function GetDrive(sDrive, sFile As String) As Boolean
Dim i As Long
For i = Asc("D") To Asc("Z")
sDrive = Chr(i) & ":\"
If GetDriveType(sDrive) = DRIVE_REMOVABLE Then
If FileExists(sDrive & sFile) Then
GetDrive = True
Exit Function
End If
End If
Next
sDrive = ""
End Function

Private Function FileExists(ByVal sFile As String) As Boolean
Dim nAttr As Long
On Error Resume Next
nAttr = GetAttr(sFile)
FileExists = (Err.Number = 0) And ((nAttr And VBA.vbDirectory) = 0)
End Function

Regards,
Peter T

"sunilpatel" wrote in message
...
I want excel to backup sheet "Record" using code but only onto a Pendrive
when a workbook is close.
The path of any removable drive may change from time to time.
Can excel extract the path names of only removable drives at any one time,
or can i somehow extract an 'identifier' on the pendrive.

Thanks guys and girls, for all your help so for. Tt's been productive.

Sunil



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
Measure on the date different Sky[_2_] Excel Worksheet Functions 4 April 4th 10 02:04 PM
Measure on the date different Sky[_2_] Excel Discussion (Misc queries) 0 March 30th 10 03:58 PM
Can I use Excel to measure time? David94 Excel Programming 3 August 30th 08 10:06 PM
Units of measure Carl07 Excel Worksheet Functions 4 October 3rd 07 01:14 AM
more ifs and an or thrown in for good measure littlebit Excel Discussion (Misc queries) 6 July 12th 05 03:05 AM


All times are GMT +1. The time now is 03:28 AM.

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"