Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 613
  • Last Modified:

MS Excel 2003, programmatically add calendar control to form using VBA

I am trying to add a Calendar Control (MSACAL) to a form using VBA  using the following:
Dim calControl As Control
Set calControl = fSetup.Controls _
    .Add("MSACAL.Calander.1", "calControl", True)

When this code runs, I receive a runtime error stating “invalid class string”:

I do have a reference to the msacal.ocx established.  Apparently, I am referencing the ProgID incorrectly.
0
ArtBarnwell
Asked:
ArtBarnwell
  • 2
1 Solution
 
yotamsherCommented:
I think you have a typo

it is MSACAL.Calendar not MSACAL.Calander

Yotam
0
 
ArtBarnwellAuthor Commented:
Yes, but I made the typo here when I created this post and not in the code.  The code as copied directly from my module is:
Dim calControl As Control
Set calControl = fSetup.Controls.Add("MSACAL.Calendar.1", "calControl", True)




0
 
yotamsherCommented:
Hey

found this code snppet in the internet (somehow I lost the link (sorry))

Dim Usf As Object
Dim Obj As MSACal.Calendar
Set Usf = ThisWorkbook.VBProject.VBComponents("Userform1")
Set Obj = Usf.Designer.Controls.Add("MSCAL.Calendar.7")
With Obj
.Left = 20: .Top = 20: .Width = 200: .Height = 150
End With
VBA.UserForms.Add (Usf.Name)
UserForms(0).Show

I can't test it right now, but it is worth a try

Yotam
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now