This is the year, but I will add something for future readers.
You will not find much documentation in the Excel help system for a 1004 runtime error, because Microsoft does not consider it an Excel error.
Answers above 100% are valid, but sometimes it helps to find out what causes the problem, so you can avoid it, fix it earlier or fix it easier.
The fact that this is an intermittent error is fixed by saving with the full path, and the file name tells me that either your macro may try to save the .xlsb file to the autocompletion directory after the files are automatically restored.
Alternatively, you can edit the file path or file name yourself.
You can check the path and file name with: - MsgBox ThisWorkbook.FullName
You should see something similar in the message box.
C: \ Users \ Mike \ AppData \ Roaming \ Microsoft \ Excel \ DIARY (version 1) .xlxb
If it is a solution (as indicated above by others) to save the file in the correct path and file name. This can be done using VBA or manually.
Now Iām used to manually saving the file with the correct path and file name, as a matter of course after any auto-discovery action, as it takes a few seconds and I find it faster (if this is not a daily occurrence). This way, macros will not encounter this error that you are running. Remember that although my habit of manually saving .xlxb files in .xlsm files right after recovery will not help the newcomer to whom you give the worksheet.
Hyperlink Note
After this error: if you have hyperlinks on the worksheet created using Ctrl + k , you will have something like "AppData \ Roaming \ Microsoft \", "\ AppData \ Roaming", .. /../AppData / Roaming / "or" .... \ My documents \ My documents \ "in several hyperlinks after the file is restored. You can avoid this by adding your hyperlinks to the text field or by creating them using the HYPERLINK function.
Identifying and recovering them is a bit more complicated.
First look at the hyperlinks and identify the error lines and the correct line for each error. Over time, I found several.
Excel does not provide tools in the Go To Special menu to search for hyperlinks created with Ctrl + k .
You can automate the identification of erroneous hyperlinks in the helper column, for example, column Z and using the formula
=OR(ISNUMBER(SEARCH("Roaming", Link2Text($C2),1)),ISNUMBER(SEARCH("Roaming", Link2Text($D2),1)))
where Link2Text is UDF
Link2Text (rng As Range) As String 'DO NOT deactivate.' Defines hyperlinks containing "roaming" in column Z.
' Identify affected hyperlinks If rng(1).Hyperlinks.Count Then Link2Text = rng.Hyperlinks(1).Address End If End Function
My error correction VBA is as follows
Sub Replace_roaming ()
'Select the correct sheet Sheets ("DIARY"). Select
Dim hl As Hyperlink For Each hl In ActiveSheet.Hyperlinks hl.Address = Replace(hl.Address, "AppData\Roaming\Microsoft\", "") Next For Each hl In ActiveSheet.Hyperlinks hl.Address = Replace(hl.Address, "AppData\Roaming\", "") Next For Each hl In ActiveSheet.Hyperlinks hl.Address = Replace(hl.Address, "../../AppData/Roaming/", "..\..\My documents\") Next For Each hl In ActiveSheet.Hyperlinks hl.Address = Replace(hl.Address, "..\..\My documents\My documents\", "..\..\My documents\") Next Application.Run "Recalc_BT" ' Move down one active row to get off the heading ActiveCell.Offset(1, 0).Select ' Check active row location If ActiveCell.Row = 1 Then ActiveCell.Offset(1, 0).Select End If ' Recalc active row ActiveCell.EntireRow.Calculate ' Notify MsgBox "Replace roaming is now complete." End Sub
I also recommend that you get used to regular backups and not rely solely on autodiscover. If this fails, you have not had anything since the last full backup.
Although the worksheet is often a fragile backup, like every hour or after a significant import of new data.
The following shortcuts will backup worksheet in seconds: Ctrl + O , [highlight file name], Ctrl + C , Ctrl + V , [X]. Regular backups allow you to immediately jump to the most recent backup without having to restore from the backup file last night, especially if you need to request another person to do this.