A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

first start of OL2007 macro VERY slow - how can I fix this?



 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old May 5th 08, 09:10 AM posted to microsoft.public.outlook.program_vba
Dan
external usenet poster
 
Posts: 35
Default first start of OL2007 macro VERY slow - how can I fix this?

hello,

I've written a small macro that starts up an addin (DesktopSMS) on the main
window toolbar from a contact form. I had to do it that way because the
addin does not provide programmatic access... :-(

anyway..
I found that the first time I start the macro after starting outlook takes
ages (3-5 minutes) and hangs OL2007 during this waiting time. however,
subsequent starts afterwards are very fast.

(I also noticed that starting the macro editior with Alt-F11 alse takes a
lot of time, though I do not know if that is related. though, after starting
the macro editor at least once, also the macro I mentioned above starts fast
the first time)

anyone can tell me how to speed up the first execution of that macro?
frankly, I am not sure that the problem is with the script.. could it be
that I have a corrupt VBAProject.otm?




the code is very simple. I'm calling DSMS_form() only from a contact form.
It grabs the mobile number from the contact, puts it on the clipboard
(because I did not find another way to send it to the DesktopSMS form
afterwards), then pushes the button DesktopSMS on the main window. I am
using another software to paste the clipboard back to the DesktopSMS form.
I know it would be more elegant to do everything in VBA, but I was simply
not finding a way to access the DesktopSMS addin directly..


Function GetCurrentItem() As Object
Dim objApp As Application

Set objApp = CreateObject("Outlook.Application")

On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = objApp.ActiveExplorer.Selection.item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
End Select

Set objApp = Nothing
End Function

Function DSMS_phone() 'get the phone number if this is a contact
Dim objItem As Object

Set objItem = GetCurrentItem()

If objItem.Class = olContact Then
With objItem
DSMS_phone = .MobileTelephoneNumber
' DSMS_email = .Email1Address 'not needed, just for fun
End With
End If

Set objItem = Nothing
End Function

Sub DSMS_button()
Dim explorer As explorer
Dim toolbars As CommandBars
Dim DesktopSMS As CommandBar
Dim SMSBtn As CommandBarButton

Set explorer = Outlook.ActiveExplorer
Set toolbars = explorer.CommandBars
Set DesktopSMS = toolbars.item("Desktop SMS")
Set SMSBtn = DesktopSMS.Controls.item("New S&MS")

SMSBtn.Execute

Set explorer = Nothing
Set toolbars = Nothing
Set DesktopSMS = Nothing
Set SMSBtn = Nothing
End Sub

Sub DSMS_form()
Call ClipBoard_SetData(DSMS_phone)
DSMS_button
End Sub


for the clipboard handling, I am using this code below I found somewhere on
the web.
I did first use the example here
http://word.mvps.org/faqs/macrosvba/...eClipboard.htm
but it did not work reliably with the ClipMagic tool I am using. the version
below has not shown any problems so far.


Option Explicit

Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) _
As Long
Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) _
As Long
Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, _
ByVal dwBytes As Long) As Long
Declare Function CloseClipboard Lib "User32" () As Long
Declare Function OpenClipboard Lib "User32" (ByVal hwnd As Long) _
As Long
Declare Function EmptyClipboard Lib "User32" () As Long
Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, _
ByVal lpString2 As Any) As Long
Declare Function SetClipboardData Lib "User32" (ByVal wFormat _
As Long, ByVal hMem As Long) As Long

Public Const GHND = &H42
Public Const CF_TEXT = 1
Public Const MAXSIZE = 4096

Function ClipBoard_SetData(MyString As String)
Dim hGlobalMemory As Long, lpGlobalMemory As Long
Dim hClipMemory As Long, X As Long

' Allocate movable global memory.
'-------------------------------------------
hGlobalMemory = GlobalAlloc(GHND, Len(MyString) + 1)

' Lock the block to get a far pointer
' to this memory.
lpGlobalMemory = GlobalLock(hGlobalMemory)

' Copy the string to this global memory.
lpGlobalMemory = lstrcpy(lpGlobalMemory, MyString)

' Unlock the memory.
If GlobalUnlock(hGlobalMemory) 0 Then
MsgBox "Could not unlock memory location. Copy aborted."
GoTo ExitHere
End If

' Open the Clipboard to copy data to.
If OpenClipboard(0&) = 0 Then
MsgBox "Could not open the Clipboard. Copy aborted."
Exit Function
End If

' Clear the Clipboard.
X = EmptyClipboard()

' Copy the data to the Clipboard.
hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)

ExitHe

If CloseClipboard() = 0 Then
MsgBox "Could not close Clipboard."
End If

End Function


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook Macro using SendKeys in OL2007... Default User Outlook - General Queries 2 May 30th 07 07:05 PM
OTL 2007 slow first start Drasko Outlook - General Queries 0 May 4th 07 09:56 PM
Outlook slow to start. Rob Outlook - General Queries 7 July 29th 06 01:27 AM
Outlook 2003 slow to start Mike_C Outlook - Installation 0 February 6th 06 08:40 AM
Outlook very slow to start on one machine, not on other Gary Hillerson Outlook - General Queries 1 January 18th 06 11:32 AM


All times are GMT +1. The time now is 08:40 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.