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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
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,224,899
Messages
6,181,629
Members
453,059
Latest member
jkevin

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