rjbinney
Active Member
- Joined
- Dec 20, 2010
- Messages
- 303
- Office Version
- 365
- Platform
- Windows
Over the years, I have built a pretty robust macro on a file to do lots of fun things - including saving some backups.
I just discovered that it isn't doing exactly what I think it should be doing - and it had been, to my knowledge for years. So I need some help testing my logic and maybe tracing the error.
When I start the Macro, here's what I want it to do:
Here's what it's saving:
Help!
I just discovered that it isn't doing exactly what I think it should be doing - and it had been, to my knowledge for years. So I need some help testing my logic and maybe tracing the error.
When I start the Macro, here's what I want it to do:
- Save the file ("Inventory Master.xlsm")
The file's current directory is c:\users\sjobs\OneDrive\Inventory Docs) - Just for giggles, save a copy in the same directory, called "Inventory Backup for Cloud.xlsm"
- Save a copy ("Inventory Backup.xlsm") on an unsyncable portion of my hard drive
- Save macro-free copies:
- "Inventory for Devices (Macro-Free).xlsx" in my original location
- "Inventory for DTG (Macro-Free).xlsx" on my external drive (which isn't always hooked up)
- "Inventory for Dropbox.xlsx" to my Dropbox
- Close the macro-free copies and open my original
Here's what it's saving:
- The current "Inventory Master.xlsm" file in the current directory, just fine
- "Inventory Backup for Cloud.xlsm" in my Dropbox (supposed to be current OneDrive directory)
- "Inventory Backup.xlsm" in the correct, unsyncable directory
- The macro-frees are off kilter:
- "Inventory for Devices (Macro-Free).xlsx" in its proper (OneDrive) location
- "Inventory for DTG (Macro-Free).xlsx" in my current OneDrive directory (it's supposed to save to an external drive)
(if the external drive is not connected, it does not save the "DTG" copy at all) - "Inventory for Dropbox.xlsx" in my Dropbox, which is correct
- The copies close and original opens.
Help!
VBA Code:
Sub SaveForDevicesFixed()
'Turn Off "Save As" Alerts
Application.DisplayAlerts = False
'Save Current
ActiveWorkbook.Save
ActiveWorkbook.SaveAs Filename:="Inventory Backup for Cloud.xlsm", FileFormat:=52
'Save Local Backup
ChDir "C:\Users\Sjobs\Documents"
ActiveWorkbook.SaveAs Filename:="Inventory Backup.xlsm", FileFormat:=52
'Strip Button
ActiveSheet.Buttons.Delete
'Save to OneDrive
ChDir "C:\users\Sjobs\OneDrive\Inventory Docs"
ActiveWorkbook.SaveAs Filename:="Inventory for Devices (Macro Free).xlsx", FileFormat:=51
'Save to Z
If XExists("Z:\Personal\Docs to Go") Then
ChDir "Z:\Personal\Docs to Go"
ActiveWorkbook.SaveAs Filename:="Inventory for DTG.xlsx", FileFormat:=51
End If
'Save to Dropbox
ChDir "C:\Users\Sjobs\Dropbox\Music"
ActiveWorkbook.SaveAs Filename:="Inventory for Dropbox.xlsx", FileFormat:=51
'Turn Alerts Back On
Application.DisplayAlerts = True
'Close the Copies and Reopen the Master
Dim ans As String
ans = "Inventory for Dropbox.xlsx"
Workbooks.Open Filename:="C:\Users\Sjobs\OneDrive\Inventory Docs\Inventory Master.xlsm"
Workbooks(ans).Close
End Sub
'Check if Z is hooked up
Private Function XExists(ByVal Path As String) As Boolean
On Error Resume Next
XExists = Dir(Path, vbDirectory) <> ""
End Function