OleObjects add monthview

K

K Warner

Using Excel 2007.
Can someone tell me how to add a MonthView oleObject to a worksheet using
VBA?
I have tried: (aSheet has been set to the ActiveSheet)
Set oleMonthView = aSheet.OLEObjects.Add _
(ClassType:="forms.MonthView")

Set oleMonthView = aSheet.OLEObjects.Add _
(ClassType:="forms.MonthView.1")

Set oleMonthView = aSheet.OLEObjects.Add _
(ClassType:="forms.microsoft monthview control")

+ a few other variations.

I always get Runtime error '1004': Cannot insert object.
 
L

Leith Ross

Using Excel 2007.
Can someone tell me how to add a MonthView oleObject to a worksheet using
VBA?
I have tried: (aSheet has been set to the ActiveSheet)
Set oleMonthView = aSheet.OLEObjects.Add _
(ClassType:="forms.MonthView")

Set oleMonthView = aSheet.OLEObjects.Add _
(ClassType:="forms.MonthView.1")

Set oleMonthView = aSheet.OLEObjects.Add _
(ClassType:="forms.microsoft monthview control")

+ a few other variations.

I always get Runtime error '1004': Cannot insert object.

Hello Kevin,

You are using the wrong object library. The Month View in not in the
Forms library but in MSComCtl2. This will inset a Month View on the
Active Sheet. Making it interactive is another issue.

ActiveSheet.OLEObjects.Add(ClassType:="MSComCtl2.MonthView")

Sincerely,
Leith Ross
 
R

RB Smissaert

When I run this code:

Sub MonthViewToSheet()

Dim oMV As OLEObject

Set oMV = ActiveSheet.OLEObjects.Add(ClassType:="MSComCtl2.MonthView")

End Sub

The Monthview is in the sheet, but it is not usable yet. Only when I move to
a different sheet
and then back to sheet with the Monthview can it be used.
What could should I use to make the Monthview usable without moving sheets?
I have tried oMV.Activate and a few other ones, but no success yet.


RBS
 
K

K Warner

This will inset a Month View on the
Active Sheet. Making it interactive is another issue.
You are right about making it interactive. I assume there is something I'm
missing.

With MonthView embedded in the WorkSheet, MonthView events are fired as
expected:

Private WithEvents myMonthview As MonthView
Private oleMonthView As OLEObject
Sub whatever()
Set oleMonthView = aSheet.OLEObjects.Item("MonthView1")
Set myMonthview = oleMonthView.Object
end sub

However, when creating a MonthView this way, the MonthView events are not
fired:
(without myMonthview_DateClick event, this is useless)

Private WithEvents myMonthview As MonthView
Private oleMonthView As OLEObject
Sub whatever()
Set oleMonthView = aSheet.OLEObjects.Add _
(ClassType:="MSComCtl2.MonthView")
Set myMonthview = oleMonthView.Object
end sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top