Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Saving to a USB drive

Hi,

I've written a macro and have gotten to the point where I'd like the macro
to save the file. I'm trying to make the macro as easy to use as possible.
To that end, I'd like the macro to save the generated file to a USB stick,
which has a drive letter that is variable. It is either E: or F:, depending
on which stick is used. The user can either save to the desktop or to the
USB key. What I'd like to happen is if the drive is not E then try F. If it
is neither, then a USB stick is not inserted and a message should pop up to
say restart the macro after inserting the stick and the macro should end.
Currently, only an error pops up to debug if no stick is inserted (which I do
not want them to do).

This is what I have so far:

' Method to save file either to USB stick or to Desktop
Dim fPath As String
fPath = "C:\Documents and Settings\" & Environ("username") & "\Desktop\"

file = ActiveWorkbook.Name
Windows("HELO Macros.xls").Activate

If Range("D3") = "To Stick" Then
Windows(file).Activate
ActiveWorkbook.SaveAs Filename:="E:\Runlogs\" & Name & "-" &
ilngFileNumber, FileFormat:=xlWorkbookNormal

ElseIf Range("D3") = "To Desktop" Then
Windows(file).Activate
ActiveWorkbook.SaveAs Filename:=fPath & Name & "-" & ilngFileNumber,
FileFormat:=xlWorkbookNormal
End If


Thank you!
Matt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Saving to a USB drive

Please do NOT save to removable data. SAVE and then COPY to wherever
desired. Reverse when you want it back.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Matt S" wrote in message
...
Hi,

I've written a macro and have gotten to the point where I'd like the macro
to save the file. I'm trying to make the macro as easy to use as
possible.
To that end, I'd like the macro to save the generated file to a USB stick,
which has a drive letter that is variable. It is either E: or F:,
depending
on which stick is used. The user can either save to the desktop or to the
USB key. What I'd like to happen is if the drive is not E then try F. If
it
is neither, then a USB stick is not inserted and a message should pop up
to
say restart the macro after inserting the stick and the macro should end.
Currently, only an error pops up to debug if no stick is inserted (which I
do
not want them to do).

This is what I have so far:

' Method to save file either to USB stick or to Desktop
Dim fPath As String
fPath = "C:\Documents and Settings\" & Environ("username") &
"\Desktop\"

file = ActiveWorkbook.Name
Windows("HELO Macros.xls").Activate

If Range("D3") = "To Stick" Then
Windows(file).Activate
ActiveWorkbook.SaveAs Filename:="E:\Runlogs\" & Name & "-" &
ilngFileNumber, FileFormat:=xlWorkbookNormal

ElseIf Range("D3") = "To Desktop" Then
Windows(file).Activate
ActiveWorkbook.SaveAs Filename:=fPath & Name & "-" & ilngFileNumber,
FileFormat:=xlWorkbookNormal
End If


Thank you!
Matt


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Saving to a USB drive

Don,

Could I get some help with the coding so that after saving to a temp file on
the hard disk I copy to the stick? Then I'd like to do the same thing... try
saving to E:, if not then F:, otherwise pop up a message and say rerun macro.

Thanks,
Matt

"Don Guillett" wrote:

Please do NOT save to removable data. SAVE and then COPY to wherever
desired. Reverse when you want it back.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Matt S" wrote in message
...
Hi,

I've written a macro and have gotten to the point where I'd like the macro
to save the file. I'm trying to make the macro as easy to use as
possible.
To that end, I'd like the macro to save the generated file to a USB stick,
which has a drive letter that is variable. It is either E: or F:,
depending
on which stick is used. The user can either save to the desktop or to the
USB key. What I'd like to happen is if the drive is not E then try F. If
it
is neither, then a USB stick is not inserted and a message should pop up
to
say restart the macro after inserting the stick and the macro should end.
Currently, only an error pops up to debug if no stick is inserted (which I
do
not want them to do).

This is what I have so far:

' Method to save file either to USB stick or to Desktop
Dim fPath As String
fPath = "C:\Documents and Settings\" & Environ("username") &
"\Desktop\"

file = ActiveWorkbook.Name
Windows("HELO Macros.xls").Activate

If Range("D3") = "To Stick" Then
Windows(file).Activate
ActiveWorkbook.SaveAs Filename:="E:\Runlogs\" & Name & "-" &
ilngFileNumber, FileFormat:=xlWorkbookNormal

ElseIf Range("D3") = "To Desktop" Then
Windows(file).Activate
ActiveWorkbook.SaveAs Filename:=fPath & Name & "-" & ilngFileNumber,
FileFormat:=xlWorkbookNormal
End If


Thank you!
Matt



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Saving to a USB drive

Why not just try writing a test file, eg

Sub test()
Dim sDrive As String

sDrive = GetEF
If Len(sDrive) = 0 Then
MsgBox "E or F not found"
Else
MsgBox sDrive
End If

End Sub

Function GetEF() As String
Dim i As Long
Dim sFile As String
Dim iFF As Integer
Const cFILE As String = ":\TestFile.tmp"
Const cTEXT As String = "This is a test file"

drv = Array("E", "F")
On Error Resume Next
For i = 0 To 1
sFile = drv(i) & cFILE
iFF = FreeFile

Open sFile For Output As #iFF
Print #iFF, cTEXT
n = LOF(iFF)
Close iFF

If n 0 Then
Kill sFile
GetEF = drv(i)
Exit For
End If
Next

End Function

Regards,
Peter T
"Matt S" wrote in message
...
Don,

Could I get some help with the coding so that after saving to a temp file

on
the hard disk I copy to the stick? Then I'd like to do the same thing...

try
saving to E:, if not then F:, otherwise pop up a message and say rerun

macro.

Thanks,
Matt

"Don Guillett" wrote:

Please do NOT save to removable data. SAVE and then COPY to wherever
desired. Reverse when you want it back.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Matt S" wrote in message
...
Hi,

I've written a macro and have gotten to the point where I'd like the

macro
to save the file. I'm trying to make the macro as easy to use as
possible.
To that end, I'd like the macro to save the generated file to a USB

stick,
which has a drive letter that is variable. It is either E: or F:,
depending
on which stick is used. The user can either save to the desktop or to

the
USB key. What I'd like to happen is if the drive is not E then try F.

If
it
is neither, then a USB stick is not inserted and a message should pop

up
to
say restart the macro after inserting the stick and the macro should

end.
Currently, only an error pops up to debug if no stick is inserted

(which I
do
not want them to do).

This is what I have so far:

' Method to save file either to USB stick or to Desktop
Dim fPath As String
fPath = "C:\Documents and Settings\" & Environ("username") &
"\Desktop\"

file = ActiveWorkbook.Name
Windows("HELO Macros.xls").Activate

If Range("D3") = "To Stick" Then
Windows(file).Activate
ActiveWorkbook.SaveAs Filename:="E:\Runlogs\" & Name & "-" &
ilngFileNumber, FileFormat:=xlWorkbookNormal

ElseIf Range("D3") = "To Desktop" Then
Windows(file).Activate
ActiveWorkbook.SaveAs Filename:=fPath & Name & "-" &

ilngFileNumber,
FileFormat:=xlWorkbookNormal
End If


Thank you!
Matt





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
Saving to USB Drive either D or E pano[_3_] Excel Programming 1 October 26th 07 11:45 AM
saving drive d maddo54 Excel Discussion (Misc queries) 0 March 13th 06 03:17 PM
Problem saving to network drive Peter Rooney Excel Programming 11 November 30th 05 01:10 PM
EXCEL saving to A: drive LindaD Excel Discussion (Misc queries) 2 October 10th 05 11:53 PM


All times are GMT +1. The time now is 04:02 PM.

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"