I'm trying to use COM to have AHK save a backup copy of my excel file every 5 minutes with a timestamp in the filename. I can get everything to work just fine with A_ variables, but when I try to use my own variables to pull the current filename and/or formatted timestamp, I get this error message:
Error: 0x800A03EC -
Source: Microsoft Excel
Description: The file could not be accessed. Try one of the
following:
. Make sure the specified folder exists.
- Make sure the folderthat contains the file is not read-only.
. Make sure the file name does not contain any of the following
characters: < > ? [ ] : | or f
. Make sure the file/path name doesn't contain more than 218
characters.
HelpFile: xlmain11.chm
HelpContext: 0
Specifically: SaveAs
LinerI
011: FormatTlme,filetimed,A_now,ddd MMM-d-yy hh:mm tt
012: MsgBothe date8ttlme is ‘%filetimed%’
014: WinGetTitle,filenamed,ahk_class XLMAIN
015: MsgBothe fliename is ‘%filenamed%’
017: monkey :- filetimed
019: XI :- Com0bJActive(‘Excel.App|lcatlon’]
020: XLVislble :- True
---> 022:
XLActiveWorkbook.SaveAs['C:\Users\Tigerlily\ExcelBackups\‘ filetimed’.xlsx')
023: Sleep,300000
024:}
025: Return
027: Return
028: {
029: MsgBox,ExceiAutoSave is no longer runningl
030: ExitApp
Continuc running the script?
Here is my current code:
Code: Select all
#SingleInstance, force ; Doesn't allow the script to run multiple instances at once.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
Loop
{
FormatTime, filetimed, A_now, ddd MMM-d-yy hh:mm tt
MsgBox, The date&time is "%filetimed%"
WinGetTitle, filenamed, ahk_class XLMAIN
MsgBox, The filename is "%filenamed%"
Xl := ComObjActive("Excel.Application") ;handle
Xl.Visible := True
XL.ActiveWorkbook.SaveAs("C:\Users\Tigerlily\ExcelBackups\" filetimed ".xlsx") ;'bookname' is a variable with the path and name of the file you desire
Sleep, 300000
}
return
End::
{
MsgBox, ExcelAutoSave is no longer running!
ExitApp
}
return