32CARDS
Board Regular
- Joined
- Jan 1, 2005
- Messages
- 123
Concept: To log a series of processes as required to a single txt file, similar to a windows log file.
Currently I use this code to "auto-save" when I require it to save and not the regular settings based on time. I need this to save the workbook when the value reaches a predtermined number, in this case it is 10.
Is there a way to have a code that will append the folowing info to a txt file.
Sub SAVE_COUNTER()
Sheets("Sheet1").Select
Sheets("Sheet1").Range("H13").Select
Sheets("Sheet1").Range("H13").Value = "AUTOSAVE COUNTER"
Sheets("Sheet1").Range("G14").Select
Sheets("Sheet1").Range("G14").Value = Sheets("ZEROWUN").Range("G14").Value + 1
If Sheets("Sheet1").Range("G14").Value = "10" Then
Sheets("Sheet1").Range("H15").Value = "SAVING WORKBOOK"
ActiveWorkbook.Save
Sheets("Sheet1").Range("H6").Value = "WORKBOOK SAVED"
Sheets("Sheet1").Range("G14").Value = "0" 'RESET TO ZERO
End If
End Sub
I am hoping the txt file to look something like this:
>20110907:11:10:28: Sub SAVE_COUNTER
>20110907:11:10:29:SAVING WORKBOOK
>20110907:11:10:30:ActiveWorkbook.Save
>20110907:11:10:45:WORKBOOK SAVED
>20110907:11:10:46:"0" 'RESET TO ZERO
It does take about 15 seconds to save this workbook, so in this case until the workbook has finished saving, the code then may continue it's Run.
So the concept would look something like,
Sheets("Sheet1").Range("G14").Select
Sheets("Sheet1").Range("G14").Value = Sheets("ZEROWUN").Range("G14").Value + 1
If Sheets("Sheet1").Range("G14").Value = "10" Then
ActiveWorkbook.Save
Log_Message 'to txt file instead "log" to a cell range
But there may be other instances to log other processes, not just the Workbook.Save
The Workbook.Save example is simply 1 of many sections of the process I need to log in txt rather than cell ranges, but the text I want logged, is in the VBA code itself
Log_Message, is the VBA "call" to start the log process
Is there a way to do this?
Currently I use this code to "auto-save" when I require it to save and not the regular settings based on time. I need this to save the workbook when the value reaches a predtermined number, in this case it is 10.
Is there a way to have a code that will append the folowing info to a txt file.
Sub SAVE_COUNTER()
Sheets("Sheet1").Select
Sheets("Sheet1").Range("H13").Select
Sheets("Sheet1").Range("H13").Value = "AUTOSAVE COUNTER"
Sheets("Sheet1").Range("G14").Select
Sheets("Sheet1").Range("G14").Value = Sheets("ZEROWUN").Range("G14").Value + 1
If Sheets("Sheet1").Range("G14").Value = "10" Then
Sheets("Sheet1").Range("H15").Value = "SAVING WORKBOOK"
ActiveWorkbook.Save
Sheets("Sheet1").Range("H6").Value = "WORKBOOK SAVED"
Sheets("Sheet1").Range("G14").Value = "0" 'RESET TO ZERO
End If
End Sub
I am hoping the txt file to look something like this:
>20110907:11:10:28: Sub SAVE_COUNTER
>20110907:11:10:29:SAVING WORKBOOK
>20110907:11:10:30:ActiveWorkbook.Save
>20110907:11:10:45:WORKBOOK SAVED
>20110907:11:10:46:"0" 'RESET TO ZERO
It does take about 15 seconds to save this workbook, so in this case until the workbook has finished saving, the code then may continue it's Run.
So the concept would look something like,
Sheets("Sheet1").Range("G14").Select
Sheets("Sheet1").Range("G14").Value = Sheets("ZEROWUN").Range("G14").Value + 1
If Sheets("Sheet1").Range("G14").Value = "10" Then
ActiveWorkbook.Save
Log_Message 'to txt file instead "log" to a cell range
But there may be other instances to log other processes, not just the Workbook.Save
The Workbook.Save example is simply 1 of many sections of the process I need to log in txt rather than cell ranges, but the text I want logged, is in the VBA code itself
Log_Message, is the VBA "call" to start the log process
Is there a way to do this?