View Full Version : Command Button - Insert Date/Time Stamp
nameltrab
02-15-2010, 12:52 PM
Hi all,
Somewhat new to VBA, I have my CommandButton - and my date time stamp command line works - but they won't work together. I am trying to get my command button to stamp date/time where the curser is located (say a specific cell in a table in Word...)
Make sense ?? I appreciate the help !
Eric
lucas
02-15-2010, 01:15 PM
Welcome to the board.
let us see your date time stamp command
when posting code, select it and hit the vba button to format it for the board.
It would help if you could post your document. click on go advanced and scroll down till you find the button that says manage attachments.
lucas
02-15-2010, 01:53 PM
If it's not in Word 2007 you can create a simple menu item that doesn't clutter up your page.
create custom menu item (http://slucas.virtualave.net/Wink/CustomMenuItem.htm)
See attached example.
nameltrab
02-15-2010, 06:01 PM
Sub PrivateSub()
Selection.InsertDateTime DateTimeFormat:="MMMM dd, yyyy hh:mm:ss", InsertAsField:=True
End Sub
So when I run that, it stamps date and time where the cursor is ... but I have to run it from inside VBA...
Private Sub CommandButton1_Click()
Selection.InsertDateTime DateTimeFormat:="MMMM dd, yyyy hh:mm:ss", InsertAsField:=True
End Sub
When I run this one, I get an error message saying "This message or property is not available because the object does not refer to a simple range or selection"
I've attached a document that has the above vba stuff, it's really nothing though, as I wanted to get the stamp working before I did any of the editing and formatting (that's the easy part!)
My goal is, for example, in the document to put the cursor in the the sample table (any cell) Click the stamp button and have it paste the date and time in that cell.
Thanks again for all the help !
nameltrab
02-15-2010, 06:05 PM
Luke - its Word 2003 - but my work is upgrading all sometime to 2007 (no date though ...) What will happen in Word 2007? ( and the stamp might work ... thanks!)
lucas
02-15-2010, 11:39 PM
I think the problem is that when you click the button, it becomes the selection so I don't see how that can work.
I tried several things like selection.insertafter and it always puts it right after the button...
I added a set of hotkeys to call your macro though. I don't see any other way to do this unless you want to put in a menu item as I have linked to the method in post #3
You can add hotkeys by going to tools-customize and select keyboard at the bottom of the dialog box. Be sure to select your document and not normal to store the shortcut in on the same dialog.
Maybe someone else will come along with a better idea.
nameltrab
02-16-2010, 03:15 AM
You're right - clicking the button would move the cursor ... Thanks for your help though !
fumei
02-16-2010, 10:10 AM
Absolutely. Clicking the button does indeed move the Selection...to the button. Therefore:
Private Sub CommandButton1_Click()
Selection.InsertDateTime yadda yadda
points to the control, where Selection is.
Steve is correct. The best way is either use a shortcut key, or any other method to fire a procedure. You could put a button on a toolbar, like the demo attached. Click the eye icon on the top toolbar.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.