vba assistance

fireslguk

Active Member
Joined
Nov 11, 2005
Messages
305
hi the following code works wonders although before creating a blank new sheet for pasting the screen grab it brings the wrong date and time.

what amendment is required to ensure the exact current time date is changed before the screen copy to paste in a new sheet

this is the code:-


Option Explicit

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_SNAPSHOT = &H2C
Private Const VK_MENU = &H12
Private Declare PtrSafe Sub Sleep Lib "kernel32.dll" ( _
ByVal dwMilliseconds As Long)



________________________________________________________________


Private Sub CommandButton2_Click()

keybd_event VK_MENU, 0, 0, 0
keybd_event VK_SNAPSHOT, 0, 0, 0
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
ActiveSheet.Unprotect "6477"
Sheets("STATUS").Range("l2").Value = Now
ActiveSheet.Protect "6477"
Sheets.Add
MsgBox ("Screen Captured - Paste to new sheet")



End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Not sure I understand. Is "Sheets("STATUS").Range("l2").Value = Now" not working?
 
Upvote 0
Do you not just need to change the location of the NOW print in the code?
Code:
[COLOR=#333333]Private Sub CommandButton2_Click()[/COLOR]
[COLOR=#333333]ActiveSheet.Unprotect "6477"[/COLOR]
[COLOR=#333333]Sheets("STATUS").Range("l2").Value = Now[/COLOR]
[COLOR=#333333]ActiveSheet.Protect "6477"[/COLOR]
[COLOR=#333333]keybd_event VK_MENU, 0, 0, 0[/COLOR]
[COLOR=#333333]keybd_event VK_SNAPSHOT, 0, 0, 0[/COLOR]
[COLOR=#333333]keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0[/COLOR]
[COLOR=#333333]keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0[/COLOR]
[COLOR=#333333]Sheets.Add[/COLOR]
[COLOR=#333333]MsgBox ("Screen Captured - Paste to new sheet")[/COLOR]

[COLOR=#333333]End Sub[/COLOR]

If not, what do you mean by the wrong date and time? how is it wrong?

LMK
Caleeco
 
Upvote 0
The date time is correct after the code has done the screen grabbing - I want the date time to be correct before the screen grab
 
Upvote 0
Hi fireslguk,

I'd be happy to help, but you first need to explain what the"correct time" means, preferably with an example.

Many Thanks
Caleeco
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

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