Object variable or with block variable not set

P

Piotr

Hi,
I have this problem every time I try to code anything more complicated
than few lines.
It occurs for example in following code. Im sure the code is right as I
use exactly same code on my second computer. This must be something in
excel options or I have no clue ????

Dim PathWinZip As String, FileNameZip As String, FileNameXls As
String
Dim ShellStr As String, strDate As String
Dim OutApp As Object
Dim OutMail As Object



PathWinZip = "C:\program files\7-zip\"
'This will check if this is the path where WinZip is installed.
If Dir(PathWinZip & "7z.exe") = "" Then
MsgBox "Please find your copy of winzip32.exe and try again"
Exit Sub
End If

' Build the date/Time string
strDate = Format(Now, "dd-mm-yy h-mm-ss")
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
<<<<<------------------------------error here
With OutMail
 
B

Bob Phillips

Do you have Outlook installed? You should check that the CreateObject action
is successful before ploughing on.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
P

Piotr

Yes I do have Outlook, but i dont know how to check if the CreateObject
is successful.
 
D

Dave Peterson

Set OutApp = nothing
on error resume next
Set OutApp = CreateObject("Outlook.Application")
on error goto 0

if outapp is nothing then
'something very bad happened
else
'it worked ok
end if
 
D

Dave Peterson

Maybe this would give a hint:

Set OutApp = Nothing
On Error Resume Next
Set OutApp = CreateObject("Outlook.Application")
If Err.Number <> 0 Then
MsgBox Err.Number & vbLf & Err.Description
Err.Clear
End If
 
P

Piotr

Hi,
This was caused by Kaspersky Antyvirus, it was keep on blocking my
macros from executing in strange way.
Thanks for help

regards
Peter
 

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