Hi again and Happy New Years' Eve!!!
So one of the first things I want to do in this little project is allow the user the opportunity to save the workbook before my code shreds through it. Some time ago I found some code on the web that worked great in another project, so I brought it over. That code is the second code block below, which is called from the first code block.
The first code block just has a very little bit extracted for I was "lucky" and that is where all of my current headache resides. As you see in the first code block I set a variable to my file-picker, then offer (and presumably run) the back-up that allows the user to choose a folder in which to place the backup by the folder-picker, and it backs up the workbook.
After that runs we are back to the first code block and the file-picker runs. BUT: IF the folder picker has run, my dang file-picker thinks it is a folder picker! If I do not run the back-up procedure, the file picker runs perfectly. What important fact am I missing?
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Set wb0 = ActiveWorkbook
If MsgBox("Would you like to create a back-up file before proceeding?", vbYesNo) = vbYes Then
Application.StatusBar = "...Please Wait - Performing Backup"
Call SaveWB
End If
'Select workbook from which to import sheets with a fail-safe to abort the sub if no file is selected
'Select the file to import from
If fd.Show = -1 Then
selFile = fd.SelectedItems(1)
Private Sub SaveWB()
Dim diaFolder As FileDialog
Dim strFolderPath As String
Dim savedate As Date
Dim savetime As Date
Dim formattime As String
Dim formatdate As String
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
' Open the file dialog
Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
diaFolder.AllowMultiSelect = False
diaFolder.Show
strFolderPath = diaFolder.SelectedItems(1)
'Saves the current file to a backup folder
savedate = Date ' Current system date
savetime = Time ' Current system time
formattime = Format(savetime, "hhMMss")
formatdate = Format(savedate, "YYMMDD")
Application.DisplayAlerts = False
ActiveWorkbook.SaveCopyAs Filename:=strFolderPath & "\" & formatdate & formattime & " " & ActiveWorkbook.Name
ActiveWorkbook.Save
Application.DisplayAlerts = True
MsgBox "Backup Run - Stored in: " & strFolderPath
End Sub
Thanks for your thoughts and Happy New Year!!!
Bookmarks