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

Problem with code



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old April 25th 08, 08:28 PM posted to microsoft.public.outlook.program_vba
somethinglikeant
external usenet poster
 
Posts: 2
Default Problem with code

I'm in the process of creating an excel spreadsheet that interacts
with Outlook via VBA.

A user is complaining of an error on the following line in VBA

qcount = Application.WorksheetFunction.CountIf(qrange, qLookfor)

I have qrange defined as a range and qLookfor as a Lookup string that
I am counting in the sheet. Can anybody see what could be causing the
problem?

Here is the full snippet of code for a feature which deletes
Appointments in Outlook based on data in the spreadsheet

------------------------------------------
Sub DeleteAppt()

Dim qrange As Range
Dim qLookfor As String

'// Ensure you write to the correct sheet
Sheets("Get Appointments").Select

'// The boring stuff
Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim olFldr As MAPIFolder
Dim olApt As AppointmentItem

Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set olFldr = olNs.GetDefaultFolder(olFolderCalendar)

'// Lookup range in sheet (unique ID range)
Set qrange = Range("L:L")
Set qdatabase = Range("L:N")

For Each olApt In olFldr.Items
'// Pick up and translate variables //
With olApt
qTask = .Subject
qDesc = .Body
qStartDay = DateValue(.Start)
qStartTime = TimeValue(.Start)
qEndDay = DateValue(.End)
qEndTime = TimeValue(.End)
'qLabel = .Categories
qShowAs = .BusyStatus
'// Convert to Desc //
If qShowAs = 0 Then xShowAs = "Busy"
If qShowAs = 1 Then xShowAs = "Free"
If qShowAs = 2 Then xShowAs = "Tentative"
If qShowAs = 3 Then xShowAs = "Out of office"
qLocation = .Location
qResource = .Resources
qTo = .OptionalAttendees
qLookfor = qStartDay + qStartTime & "/" & qEndDay +
qEndTime & "/" & qTask & "/" & qShowAs
'// Condition 1: qLookfor is in qrange //
On Error Resume Next
qcount = Application.WorksheetFunction.CountIf(qrange,
qLookfor)
If Err.Number 0 Then MsgBox "Error Counting in " & "
Column L", vbCritical, "ExcelToOutlookTaskSynch"
On Error GoTo 0

If qcount 0 Then
'// Condition 2: Corresponding Delete Flag = Y //
qDelete =
Application.WorksheetFunction.Index(qdatabase,
WorksheetFunction.Match(qLookfor, qrange, 0), 3)
If qDelete = "Y" Then
.Delete
End If
End If
End With
Next olApt

Set olApt = Nothing
Set olFldr = Nothing
Set olNs = Nothing
Set olApp = Nothing


Call GetAppt

End Sub
------------------------------------------

Any help appreciated,

Thanks,

Anthony
  #2  
Old April 25th 08, 09:07 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Problem with code

Since that's an Excel issue, I'd suggest you ask in an Excel forum. Be sure to give details of any error message you're getting and your Excel version.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"somethinglikeant" wrote in message ...
I'm in the process of creating an excel spreadsheet that interacts
with Outlook via VBA.

A user is complaining of an error on the following line in VBA

qcount = Application.WorksheetFunction.CountIf(qrange, qLookfor)

I have qrange defined as a range and qLookfor as a Lookup string that
I am counting in the sheet. Can anybody see what could be causing the
problem?


 




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
Problem using Outlook Redemption VBA code [email protected] Outlook and VBA 8 June 7th 07 04:00 AM
Problem with leading zeros in the area code in Contact's phone numbers. Alan Outlook - Using Contacts 1 April 13th 07 04:40 PM
Problem with Code - converting emails to .htm files jpotucek Outlook and VBA 8 April 26th 06 06:01 PM
Distr List, Code execution speed problem saeongjeema via OfficeKB.com Outlook and VBA 2 March 27th 06 08:15 PM
code : Code : 800cccd2 scotty971fr Outlook Express 1 January 19th 06 11:59 PM


All times are GMT +1. The time now is 11:35 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.