LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Problem with VBA code - Can't figure out what is wrong

I haven't worked across applications in quite a while, but without walking
through the procedure, I would guess that the focus is still on the Outlook
file and not the
Excel sheet.

"excel-ant" wrote:

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

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA: cannot figure out code Tom Excel Programming 1 July 20th 07 08:28 PM
Unable to figure out VBA Code needed Kieranz[_2_] Excel Programming 3 March 5th 07 01:34 PM
Vlookup - can't figure out what's wrong pm Excel Worksheet Functions 5 December 15th 06 08:02 PM
Code to Save As, then Open - can't figure it out! [email protected] Excel Discussion (Misc queries) 0 May 25th 06 09:18 PM
Can anyone figure this code problem please simonsmith Excel Discussion (Misc queries) 1 May 18th 06 08:20 PM


All times are GMT +1. The time now is 06:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"