1

How can I add a DateTimePicker to a User Form using VBA code.

Similar to adding a Label -

Dim TempForm As Object
Dim NewLabel as MSForms.Label

 Set NewLabel = TempForm.Designer.Controls.Add("Forms.label.1")
Community
  • 1
  • 1
vkrams
  • 7,267
  • 17
  • 79
  • 129
  • 3
    Vikram, I wouldn't recommend using the DateTimePicker as you cannot freely distribute the control. The enduser might not have the OCX registered. If you are interested in an alternative then have a look at my reply for showing dates in a userform in this link http://stackoverflow.com/questions/12012206/formatting-mm-dd-yyyy-dates-in-textbox-in-vba – Siddharth Rout Sep 04 '12 at 07:51
  • Thanks Siddharth ...looks nice !! – vkrams Sep 04 '12 at 08:19
  • Hi Siddharth , in the component which you had shared , the QueryClose event is not being executed ,and I see many temp worksheets created in my project. Also I removed the textbox , OK and Cancel buttons from the form as I dont need them . And included Unload Me in every other button click event.Any idea why this is happening ? – vkrams Sep 05 '12 at 10:37
  • I changed xlSheetVeryHidden to xlSheetHidden and ws.Delete works... – vkrams Sep 05 '12 at 11:12

1 Answers1

0

Actually, I have got the answer from this question in the sidharth

Formatting MM/DD/YYYY dates in textbox in VBA

Community
  • 1
  • 1
vkrams
  • 7,267
  • 17
  • 79
  • 129