is it possible to make the logfile, save automatic with out having to interfere with the computer?
#RumbaHi Besafe,
if the macro is stopped while the logfile is Open, then it will be locked for editing. So you will need to tell it to close.
Normally one would do this at the start of the macro, i.e. issue a Close command (no parameters). This should close any file left open from a prior run.
Then you can use a timestamp in your logfile name.
To minimise the likely hood of the logfile being open when you manually stop the macro you can try to reduce the number of times that you write to the log and always close and reopen the log file before and after each write to it.
So the first time you open a file you open it for Output, then before subsequent writes you open it for Append.
Ideally you should create a small subroutine to handle logging.
e.g. AppedToLogfile(MyMessage as String)
Then in this subroutine you open for append, write to the logfile and close it.
In your main routine you would then open for Output and Close it, subsequently you'd simple call AppendToLogfile and pass the string you which to write into the logfile.
Tom
is it possible to make the logfile, save automatic with out having to interfere with the computer?
#RumbaHey, Tom
i read somewhere that it would be possible to use a command such as:
XLSheet.Application.Visible = True ' Show the EXCEL sheet
MyBook.SaveAs("H:\\MyPersonalData\\Documents\\tryg scripts\\anders\\")
however it only opens and shows the logfile, and not also saving it for me automatically, do you know anything about this?
is it possible to make the logfile, save automatic with out having to interfere with the computer?
#RumbaHi Besafe
Here is some sample code
Sub Main
Set objExcel = CreateObject("Excel.Application")
Set objDoc = objExcel.Workbooks.Add
objExcel.Visible = True
objExcel.Application.DisplayAlerts = False
objExcel.ActiveWorkbook.SaveAs FileName:="C:\\temp\\Besafe.xlsx", FileFormat:=51
objExcel.ActiveWorkbook.Close SaveChanges:=False
objExcel.Application.DisplayAlerts = True
objExcel.Quit
End Sub
That should save the workbook as a .xlsx file and exit Excel. If you wish to have a .xlsm format the change to FileFormat:=52
Note: The DisplayAlerts bit prevents the overwrite dialog from appearing when you attempt to save.
Tom