OS specific VBA? (repost under a different title)

C

CarolChi

Does anyone know if there are OS related differences in Outlook?

I'm trying to move to the next item in the Inbox.
The code below always works when Outlook is freshly opened.

When working in a TS session on 2003 Server SP1, and on Vista beta version
5219, the penultimate line returns a "type mismatch" when I have done
anything else in Outlook before running the code. It works fine when Outlook
has just been opened.

Dim oInbox As Outlook.MAPIFolder
Dim olApp As Application
Dim olNameSpace As NameSpace

Set olApp = CreateObject("Outlook.Application")
Set olNameSpace = olApp.GetNamespace("MAPI")
Set oInbox = olNameSpace.GetDefaultFolder(olFolderInbox)
Set ActiveExplorer.CurrentFolder = oInbox

Set olPop = Application.ActiveInspector.CommandBars.FindControl(, 360)
Set olCmd = olPop.Controls(1)

Carol
 
M

Michael Bauer

Am Wed, 19 Oct 2005 23:34:02 -0700 schrieb CarolChi:

Where/what is your declaration for olPop? Does the error occur only if the
currentfolder isn´t the inbox already?

Ken asked you for a recursive search, why don´t you follow that thread?
 
C

CarolChi

Dim olCmd As Office.CommandBarButton
Dim olPop As Office.CommandBarPopup

Have not yet had time to do the recursive search. I'm also trying to identiy
the OS issues.
 
M

Michael Bauer

Am Thu, 20 Oct 2005 02:33:04 -0700 schrieb CarolChi:


Dim olCmd As Office.CommandBarButton
Dim olPop As Office.CommandBarPopup

Have not yet had time to do the recursive search. I'm also trying to identiy
the OS issues.

Hm, if you don´t have the time - who else should have it?

I´m quite sure there´s no OS issue at all. Please check the by
FindControl(,360) returned object type and compare it with your olPop
declaration. Then you´ll see your mistake.
 
K

Ken Slovak - [MVP - Outlook]

The placement of the toolbars and so on can vary so that's why recursive is
used. Then it doesn't matter at what depth the item is located. Using a
recursive search in FindControl is as simple as setting that argument =
True, so I'd do that first before anything and see if your problems go away.
It doesn't take much time and if you don't have the time for it I'm sure no
one else would.
 
C

CarolChi

I did not mean I do not have any time, just did not have any this morning.
Sorry to be such a pain.

I added the recursive argument but it won't run: Compile error: wrong number
of arguments or invalid property assignment.

The visual prompt as I type the command does not show recursive, the last
argument, only Type, ID, Tag, Visible. Help does show recursive as an
argument.

Here is the declaration :

Dim olCmd As Office.CommandBarButton
 
K

Ken Slovak - [MVP - Outlook]

A button doesn't have a FindControl method. CommandBar.FindControl is what
you want. It has the following arguments (in order): Type, ID, Tag, Visible,
Recursive.

If you want to skip some arguments the best way to make sure you aren't
putting things in the wrong order is to use named arguments:

oBar.FindControl(Id := 500, Recursive := True) '500 is an arbitrary number

CommandBars.FindControl doesn't have a Recursive argument, so what you want
to do is to set up a CommandBar object based on "Menu Bar" and search that
recursively. If you want something on the Standard or Advanced toolbars then
just use those instead of Menu Bar.
 
C

CarolChi

Let me try and be coherent and complete:

Dim olCmd As office.CommandBarButton
Dim olPop As office.CommandBarPopup
Dim oInbox As Outlook.MAPIFolder
Dim olApp As Application 'Outloook application
Dim olNameSpace As NameSpace
Set olApp = CreateObject("Outlook.Application")
Set olNameSpace = olApp.GetNamespace("MAPI")
Set oInbox = olNameSpace.GetDefaultFolder(olFolderInbox)
Set ActiveExplorer.CurrentFolder = oInbox
Set olPop = Application.ActiveInspector.CommandBars.FindControl(, 360)
...
Set olCmd = olPop.Controls(1)
olCmd.Execute

the FindControl line fails with a 13 type mismatch (last line) on some
systems if I have moved around in Outlook before running the code.

If I try to add the recursive argument
Set olPop = Application.ActiveInspector.CommandBars.FindControl(, 360,,True)
It fails again (same line) with
Compile error: wrong number
of arguments or invalid property assignment.
 
M

Michael Bauer

Am Sun, 23 Oct 2005 10:38:03 -0700 schrieb CarolChi:

What are you still looking for? Error 13 doesn´t say that control 360 isn´t
found, but that it´s another object type than your declared CommandBarPopup.

As you´ve experienced there´re two different object types with the same
id=360. So one simple approach is this:

Dim obj as Object
Dim cbb as Office.CommandBarButton
Set obj=FindControl...
If Not obj Is Nothing Then
If TypeOf obj is Office.CommandBarPopup Then
' look for the button in the popup´s childs
Else
' The button is already found
Set cbb=obj
Endif
Endif

Another approach would be to search the control explicitly either in the
Standard Bar or Menu Bar:

The Standard Bar contains the "Next Item" (?) CommandBarPopup. Both the
Popup and its default CommandBarButton have the same id=360.

Additionally there´s almost the same structure of controls contained in the
Menu Bar. The difference is that this CommandBarPopup has the id=30117. Its
default CommandBarButton has also the id=360.

So obviously once your FindControl returns the CommandBarPop (id=360) and
the other time it returns the CommandBarButton (id=360).
 
K

Ken Slovak - [MVP - Outlook]

And if you define olPop as Object? If that works then you've declared the
item as the wrong type.

There can also be context issues. The most prominent is the Actions menu,
where there are actually multiple Actions menus each with a different ID and
each active under different contexts (mail folder, tasks folder, etc.).
 

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