Simulating a double click in VBA

Solved
nomitse Posted messages 7 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
Configuration: Windows XP / Firefox 3.5.7

4 answers

  1. eriiic Posted messages 24581 Registration date   Status Contributor Last intervention   7 281
     
    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
    2
  2. Gord21 Posted messages 928 Status Member 289
     
    Hello,

    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
    0
  3. nomitse Posted messages 7 Status Member
     
    I tried both, neither works.

    I don't understand...
    0
    1. Gord21 Posted messages 928 Status Member 289
       
      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:
      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
      0
  4. nomitse Posted messages 7 Status Member
     
    It works!!

    Thank you very much.

    Simon
    0
    1. Gord21 Posted messages 928 Status Member 289
       
      Hello,
      For your information, to select your date you have the option to display a calendar in your UserForm. You select Tools/Additional Controls and add Calendar Control: a new calendar control will appear in your tools menu.

      --
      Experience: the name by which men baptize their mistakes.
      Oscar Wilde
      0