PDA

View Full Version : Solved: Macro problem



Pat
06-03-2005, 04:03 AM
I have made a macro in outlook 2003 and now i have a problem with it on only one machine. When macro need access to mails i should get a warning "A program is trying to access e-mail addresses you have stored in Outlook. Do you want to allow this?" but int this case nothing happens, please tell me how can i test this . I phoned to M$ and they told me that there is no way to block this warning so this is a macro problem, does anybody know how can i solve this problem ??
Security level i set to medium and macro runs but when it's trying to get to mails nothing happens, somewhere this access is blocked. Ealier this macro worked on this computer without any problems.

Dim myItems, myItem, myAttachments As Object
Dim str, str2 As String
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim objMail As Outlook.MailItem


On Error Resume Next

'work on selected items
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
Set objMail = myOlApp.CreateItem(olMailItem)

k = 1
'for all items do...
For Each myItem In myOlSel

With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.HTMLBody = myItem.HTMLBody +
.Subject = myItem.Subject
For i = 1 To myAttachments.Count

myAttachments(i).SaveAsFile ("c:\windows\Temp\" & myAttachments(i).DisplayName)
.Attachments.Add ("c:\windows\Temp\" & myAttachments(i).DisplayName)


Next i

.Save

End With
Next
End







i know that this code could be much simple but i'm new to VBA :)
All i need is to get mail, copy it with attachments add some values from simple form and send it to a certain address, this macro above does it but (i didn't paste all code only the most important part :)) but if you know easier way to accomplish this task i will be very thankful.

Killian
06-03-2005, 07:37 AM
This message is part of an MS security update and is not something that can be switched off.
However, there are ways around most things...
This subject is discussed towards the end of this (http://www.vbaexpress.com/forum/showthread.php?t=2700) thread.
You might also want to take a look here (http://www.dimastr.com/redemption/) for another option.

avkb03
06-03-2005, 08:02 AM
Redemption is the answer...
http://www.dimastr.com/redemption/

MOS MASTER
06-03-2005, 01:07 PM
Hi And Welcome to VBA, :hi:

The boys seam to think your problem is with the security message popping up ...well I think you mean the Error isn't comming at all and you think its strange?

So It could well be that your macro doesn't get firred at all? (Or does something you didn't think of...)

To make sure it's fired just put a simple message box at the top of your code like:
MsgBox "I'm Working"


If you want your code written more efficiently I sugest you paste the entire code over here (With supporting functions if any) or export the codemodule and Attach it (Zipped) to this topic.

For us to rewrite we need to see what your code is doing now..we can see some of it in the code but some clarification of how the code should work (work flow) would be smart because your code might well be doing something you didn't exspect?

Later...:whistle:

Pat
06-06-2005, 03:02 AM
Thanks for help i'm not sure in 100% but i think i found the cause of my problem. Path c:\windows\temp is wrong, i mean users don't have write permissions to this directory, which is funny because this macro worked earlier when i changed it to different directory it worked. I didn't test it yet on all machines but i think this is the problem. I will use your advices when i will be writing version 2.0 :). Of course i will let you know if everything will be ok. One more time thanks.

Killian
06-06-2005, 05:21 AM
OK,
well you can get the current users windows temp file path by usingUSERS_FILE_PATH = Environ("TEMP")

Pat
06-06-2005, 07:45 AM
Hello,

unfortunately changing path didn't help me, but i know where the problem is, i have made many tests and found out that selection doesn't work when i try to test it with

MsgBox myItem.Subject
or even
MsgBox myAttachments(i).DisplayName



i get nothing, of course MsgBox "test" works :thumb. This is very weird because this macro works very well on other machines. I don't have any idea what's going on :dunno

Killian
06-06-2005, 08:05 AM
Is there any difference between this PC and all the others (Outlook version/ build, OS, Outlook secutiry settings, etc)
If you take out the "On Error Resume Next" line you'll be able trap where the error is occurring. I suspect it will be when the objects are set (active explorer or selection) which would explain the empty MsgBox.
You'll also get an error number and description, which will help.

MOS MASTER
06-06-2005, 09:25 AM
Hi, :yes

The bit of code you posted first looks a bit strange to me. (couldn't be sure because haven't seen the rest)
If you could post the entire code (Or attach the Bas file) I'm sure we can figure out what's happening.

Later. :whistle:

Pat
06-07-2005, 01:58 AM
OK. i have deleted 'On error resume next' and i got error like this
Run-time error '-2147024770 (8007007e)'
Automation error
and information that module cannot be found

when i clicked debug this part of code was mark yellow.
Set mOlExp = myOlApp.ActiveExplorer
and below i paste my code, as i wrote in previous post it works on any other machine


Dim myItems, myItem, myAttachments As Object
Dim str, str2 As String
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim objMail As Outlook.MailItem


On Error Resume Next

'work on selected items
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
Set objMail = myOlApp.CreateItem(olMailItem)

k = 1
'for all items do...
For Each myItem In myOlSel
Set myAttachments = myItem.Attachments
With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.HTMLBody = myItem.HTMLBody +
.Subject = myItem.Subject
For i = 1 To myAttachments.Count

myAttachments(i).SaveAsFile ("c:\windows\Temp\" & myAttachments(i).DisplayName)
.Attachments.Add ("c:\windows\Temp\" & myAttachments(i).DisplayName)


Next i

.Save

End With
Next
End

Killian
06-07-2005, 02:42 AM
so which version of Outlook is this... the Explorer object wasn't available in OL97 (i'm not sure when it was introduced)

Pat
06-07-2005, 02:50 AM
Outlook 2003, i have only office 2003 in my work.

Killian
06-07-2005, 03:02 AM
Seems a bit strange...Could it be that there's no explorer active when you run this?

Pat
06-07-2005, 03:44 AM
What do you mean by

Could it be that there's no explorer active when you run this?

i know it's strange, i checked the event viewer and nothing, maybe repairing office will help??:help

MOS MASTER
06-07-2005, 10:21 AM
OK. i have deleted 'On error resume next' and i got error like this
Run-time error '-2147024770 (8007007e)'
Automation error
and information that module cannot be found

when i clicked debug this part of code was mark yellow.
Set mOlExp = myOlApp.ActiveExplorer
and below i paste my code, as i wrote in previous post it works on any other machine

Hi I've looked for this perticular error and it has to do something with the creation of a new Outlook Object. (Via Early binding your method or via late binding)

It seams to happen a lot when people have upgraded from 2002 to 2003 and not fully uninstalled the previous version.
Here a small discussion: Click here (http://groups.google.nl/group/microsoft.public.office.developer.outlook.vba/browse_thread/thread/5da195a226f8430d/a2b6b661703f994f?q=Outlook+Error+The+specified+module&rnum=7&hl=nl#a2b6b661703f994f)

Mean while perhaps you don't need to create a new outlook application and you can just use the current one like:

Set mOlExp = Application.ActiveExplorer
Try it and tell us if this helps?

Later..:whistle:

Pat
06-08-2005, 04:20 AM
Thank you very very much it worked :thumb

MOS MASTER
06-08-2005, 09:32 AM
Thank you very very much it worked :thumb
Where glad to help! You're Welcome! :beerchug:

Don't forget to mark your thread solved?