Simulating a double click in VBA
Solved
nomitse
Posted messages
7
Status
Member
-
Gord21 Posted messages 928 Status Member -
Gord21 Posted messages 928 Status Member -
Hello,
I created a Userform with a text box where a date needs to be entered. With a button, I exported this date to a specified cell. I previously customized the cell format to display the date as follows: yyyy-mmm-dd
Everything works well and my date is exported to the requested cell, but the format is not taken into account. It is indeed correctly set up in the cell when I check my custom cell format.
To properly display my date, I have to double-click on the cell and press Enter. Only then does the correct format take effect.
That's why I'm reaching out to you to find a command that allows me to simulate a double-click on the cell. Or any other solution as long as it works.
Thank you in advance.
simon
I created a Userform with a text box where a date needs to be entered. With a button, I exported this date to a specified cell. I previously customized the cell format to display the date as follows: yyyy-mmm-dd
Everything works well and my date is exported to the requested cell, but the format is not taken into account. It is indeed correctly set up in the cell when I check my custom cell format.
To properly display my date, I have to double-click on the cell and press Enter. Only then does the correct format take effect.
That's why I'm reaching out to you to find a command that allows me to simulate a double-click on the cell. Or any other solution as long as it works.
Thank you in advance.
simon
Configuration: Windows XP / Firefox 3.5.7
4 answers
Hello,
I believe it was mainly the cdate() mentioned by gord21 that was missing; normally, it's not necessary to redefine the cell format.
eric
I believe it was mainly the cdate() mentioned by gord21 that was missing; normally, it's not necessary to redefine the cell format.
eric
Hello,
You can try:
where A1 corresponds to your cell.
Otherwise, you can try:
but I’m not sure it will work for the format
--
Experience: the name by which men call their mistakes.
Oscar Wilde
You can try:
Range("A1").Select Application.DoubleClick where A1 corresponds to your cell.
Otherwise, you can try:
Range("A1").Calculate but I’m not sure it will work for the format
--
Experience: the name by which men call their mistakes.
Oscar Wilde
I don't understand, I tried setting your format on cells A1 and A2, and I left Standard on the others, then I ran the code:
And it works for me (for the format, there's still a day/month setting to be done)
How is your date entered (a day field, a month, a year and you recombine, or???)
--
Experience: a name that men use to baptize their mistakes.
Oscar Wilde
Dim test As String test = "12/01/2010" Range("A1").Value = test Range("A2").Value = CDate(test) Range("B1").Value = test Range("B1").NumberFormat = "yyyy-mmm-dd" Range("B2").Value = CDate(test) Range("B2").NumberFormat = "yyyy-mmm-dd" And it works for me (for the format, there's still a day/month setting to be done)
How is your date entered (a day field, a month, a year and you recombine, or???)
--
Experience: a name that men use to baptize their mistakes.
Oscar Wilde