Detecting if floppy disk is in drive

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
20,348
Office Version
  1. 365
Platform
  1. Windows
I'm trying to make it so that a backup copy of my file is written to floppy when the file is saved (but not with SaveAs). So far, I have the following code, which if the floppy is in the drive works fine, and doesn't error out if the disk is not in the drive. But it doesn't make sure that a backup copy actually got made. How would I check to see if the disk is in the drive and loop somehow until it was so that the file got saved to floppy?

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
On Error Resume Next
Application.DisplayAlerts = False
    If Not (SaveAsUI) Then
        MsgBox "Please Insert Floppy Disk in Drive A:"
        ThisWorkbook.SaveCopyAs "A:\" & ThisWorkbook.Name
    End If
Application.DisplayAlerts = True
End Sub
 
I think this might be what you are after if I understand the issue correctly:


Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Not (SaveAsUI) Then

Dim MyDrive$, MyDriveDir$
MyDrive = "A"

While Err.Number = 0
On Error Resume Next
MyDriveDir = Dir(MyDrive & ":\", 5)

If MyDriveDir = "" Or IsError(MyDriveDir) Then
MsgBox "Click OK and you'll have another 10 seconds" & vbCrLf & _
"to put a disk in that drive.", 48, "No disk is in Drive " & MyDrive & "."
Application.Wait (Now + TimeSerial(0, 0, 10))
Err.Clear

Else
MsgBox "Drive " & MyDrive & " has a disk and the file is being saved.", , "Thank you"
Cancel = True
Application.EnableEvents = False
ThisWorkbook.SaveCopyAs "A:\" & ThisWorkbook.Name
Application.EnableEvents = True
Exit Sub

End If
Wend
End If

End Sub
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
That seems to be a lot more code than this:

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) 
Dim oFilesysObject As Object 
Set oFilesysObject = CreateObject("Scripting.FileSystemObject") 
If Not (SaveAsUI) Then 
    Do 
        MsgBox "Please Insert Floppy Disk in Drive A:" 
    Loop Until oFilesysObject.GetDrive("A:\").IsReady 
    ThisWorkbook.SaveCopyAs "A:\" & ThisWorkbook.Name 
End If 
End Sub

Is there a significant disadvantage to doing it this way?
I also don't think I want to set Cancel to True, I want it to save in the normal fashion to where the file normally is on the C: drive as well as make a copy to the floppy.
 
Upvote 0
I guess it comes down to a matter of design preferences for what users might like to see. Also, I never create system objects in code unless I need to, not saying anything's wrong with anyone else's code, just my preference.
 
Upvote 0

Forum statistics

Threads
1,215,357
Messages
6,124,482
Members
449,165
Latest member
ChipDude83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top