Vba log file

MetLife

Active Member
Joined
Jul 2, 2012
Messages
283
Hi,

Is there a log file available in VBA? I could put the log in the worksheet but wanted to know if there were other options.

Thanks
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I'm not sure if this is what you're trying to achieve - but you can get VBA to write to a file as the code progresses. Here is a very basic example which creates a file called LogFile.txt and logs the user's input. In theory you could write anything known by the macro to it:
Rich (BB code):
<code>
'Open (create) the file you want to write to, near start of macro
Open "C:/LogFile.txt" For Append As #1 

'Ask user to enter some text so we can log what they input
ReplyToLog = InputBox("Enter some text")

'Create Log entry with timestamp
MyLogEntry = Format(Now, "dd/mm/yyyy hh:mm:ss") & " - User input: " & ReplyToLog
Print #1 , MyLogEntry

'Repeat the above for as many logs as you need

'Close the log file near the end of the macro
Close #1
This example adds entries to the end of the existing log file. If you want to create a new log file (overwriting the previous) each time, change Append to Output.

You must close the file in the macro. I usually also create a separate macro just containing the
Rich (BB code):
Close #1
line, which I can use during testing if the main macro crashes whilst the file is still open.</code>
 
Last edited:
Upvote 0
.
What are you wanting to log ?

Will the user be inputting the data or is the log capturing what the user is doing without his/her knowledge ?

Please be more descriptive.
 
Upvote 0
.
What are you wanting to log ?

Will the user be inputting the data or is the log capturing what the user is doing without his/her knowledge ?

Please be more descriptive.

Its a log file for a software program.

The log describes things that happen, like errors or reading files. Its the same type of logs you see in other systems.
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,249
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top