Log when printing

Craig1

Active Member
Joined
Jun 11, 2009
Messages
322
Hi guys,

I use the code below:-

Private Sub Workbook_Open() With Worksheets("Log")
EndRow = Sheets("Log").Range("A65536").End(xlUp).Row + 1
Sheets("Log").Range("F" & EndRow).Value = Environ("USERNAME")
Sheets("Log").Range("A" & EndRow).Value = Now()

End With
End Sub


This documents who has logged into the workbook. I want to use something similar when a document is printed. All I need is the date and username (as above). When command button1 (which prints a word doc) is pressed I want the info to go into column C for the user and the date in column D.

Any help would be appreciated.

Craig.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Maybe:
Rich (BB code):
    With Sheet2 '<---CodeName or Sheet/Tab name ---> ThisWorkbook.Worksheets("Sheet2")
        .Cells(.Rows.Count, "C").End(xlUp).Offset(1).Resize(, 2).Value _
            = Array(Environ("UserName"), Date)
    End With
End Sub
 
Upvote 0
Hi Guys,

I got the code to work when I changed a cell but not when I printed using the command button. It did also put the user name and date in another 200+ cells in the same columns.

Can excel extract the info it needs from the press of a command button or is it just a change in a cell.

Any ideas guys. All help welcome and appreciated.

Craig.
 
Upvote 0
...When command button1 (which prints a word doc) is pressed I want the info to go into column C for the user and the date in column D...

I got the code to work when I changed a cell but not when I printed using the command button. It did also put the user name and date in another 200+ cells in the same columns...

Hi Craig,

Can you show us the code you currently have for the button's click event?

Mark
 
Upvote 0
Hi Mark,
Thanks for the reply, I got it to work by adding the the code below (and modifying) to the actual command button. So when it actually does the print it puts the user name and date where i need it.

EndRow = Sheets("Log").Range("A65536").End(xlUp).Row + 1
Sheets("Log").Range("F" & EndRow).Value = Environ("USERNAME")
Sheets("Log").Range("A" & EndRow).Value = Now()

So all's well that ends well.

Again, thanks for all the help.

Craig.
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,898
Members
452,948
Latest member
Dupuhini

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