View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Copy to a flash drive

If I understand correctly, you can use either of the following
procedures to copy the workbook ThisWorkbook to a flash drive,
assuming you know the drive letter of the flash drive.


Sub AAA()
Dim SaveFileName As Variant
Dim FlashDrive As String
FlashDrive = "K:\"
SaveFileName = Application.GetSaveAsFilename(FlashDrive, _
"Excel Files (*.xls;*.xlsx;*.xlsm),*.xls;*.xlsx;*.xlsm")
If SaveFileName = False Then
Debug.Print "cancelled"
Else
ThisWorkbook.SaveCopyAs SaveFileName
End If
End Sub

Sub BBB()
Dim FlashDrive As String
FlashDrive = "K:\"
With ThisWorkbook
.ChangeFileAccess xlReadOnly
FileCopy ThisWorkbook.FullName, FlashDrive & "\" & _
ThisWorkbook.Name
.ChangeFileAccess xlReadWrite
End With
End Sub

As an alternative, you can display a Browse Folder dialog to the user,
let him pick the root of the flash drive and SaveCopyAs to that
folder. E.g.,

Sub CCC()
Dim FolderName As String
FolderName = BrowseFolder("Select the flash drive's root.")
If FolderName = vbNullString Then
Debug.Print "cancel"
Else
ThisWorkbook.SaveCopyAs FolderName & "\" & ThisWorkbook.Name
End If

End Sub

The BrowseFolder function is described at
http://www.cpearson.com/excel/BrowseFolder.aspx

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Mon, 22 Dec 2008 17:59:00 -0800, ypukpete
wrote:

i am using Excel 2003. I am looking for VBA code which I can use with a
command button which will open the Copy-to Window so that I can copy the
workbook I have open to a Flash Drive in a USB port. All help gratefully
accepted
Thanks.