Solved

Convert VBA from outlock to vb script

Posted on 2008-06-16
12
163 Views
Last Modified: 2013-11-26
Hi!

In outlock you have a function to save email as MSG file.
I can make a function in vba in outlock for this job:

Dim Message As MailItem
Dim t1 As Integer
Dim s1 As String

Set myNameSpace = Application.GetNamespace("MAPI")
'Set myJobber = myNameSpace.GetDefaultFolder(olFolderJobber)
Set myInboks = myNameSpace.GetDefaultFolder(olFolderInbox).Folders("test1")
t1 = 1
s1 = "Fil"

For Each Message In myInboks.Items
      s1 = s1 & Str(t1)
      Message.SaveAs "C:\tt1\" & s1 & ".msg", olMSG
      s1 = Message.MarkForDownload
           
      s1 = "Fil"
      t1 = t1 + 1
Next Message


But need to have the same function in VB.SCRIPT
Is this possible in VB.SCRIPT ?

Please help ASAP

0
Comment
Question by:team2005
  • 6
  • 6
12 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
Comment Utility
Hi team2005.

This should do it.
Const olFolderInbox = 6

Dim Message

Dim t1

Dim s1
 

Set olkApp = GetObject(,"Outlook.Application")

Set myNameSpace = olkApp.GetNamespace("MAPI")

Set myInboks = myNameSpace.GetDefaultFolder(olFolderInbox).Folders("test1")

t1 = 1

s1 = "Fil"
 

For Each Message In myInboks.Items

      s1 = s1 & Str(t1)

      Message.SaveAs "C:\tt1\" & s1 & ".msg", olMSG

      s1 = Message.MarkForDownload

           

      s1 = "Fil"

      t1 = t1 + 1

Next Message

Open in new window

0
 
LVL 2

Author Comment

by:team2005
Comment Utility
Hi!

Tryed your code, but get a error message:

Error message is : Expected end of statment

Here ---> End Message     (gives the error)

???
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
"Here ---> End Message"
Sorry, I don't see that anywhere in the code.  Can you give me a line number?
0
 
LVL 2

Author Comment

by:team2005
Comment Utility
Hi!

Sorry , my mistace

Next Message  ---> Line 19
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Well, that's your code.  I just made the changes necessary to run from VBScript.  I made no change to that line nor to the loop it's a part of.  If it fails in VBScript, then it should fail int he VBA original too.  That aside, I don't see why it should fail.  That type of FOR ... NEXT loop should never fail so long as no items are being removed from the original collection.  I don't see any Delete or Move commands, so that shouldn't be the case.
0
 
LVL 2

Author Comment

by:team2005
Comment Utility
Hi!

When i tryed your code in VBA in outlock.
Its working just fine, so what is the different
using VB.SCRIPT ???

Strange....
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Good question.  Try taking Message off of line 19, leaving just Next.
0
 
LVL 2

Author Comment

by:team2005
Comment Utility
Hi!

Tryed to remove Message like you say.
And now its making the files.
But when i dobbelclick the created file, it do not show this email
in outlock. But give me a message like:

Cannot open file <filename> The file may not exist , you may not have permission to open it, or it may be
open in another program. Right click the folder that contains the file , and then click Properties to check
your permissions for the folder.

Why dosent this work, when the same code work in outlock ???

Very very strange



0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Ummm, I think I missed something.  Add this line to the top of the file.

Const olMSG = 3
0
 
LVL 2

Author Comment

by:team2005
Comment Utility
Hi!

YES, its working now.

Thank you so mutch for BIG help
0
 
LVL 2

Author Closing Comment

by:team2005
Comment Utility
Thanks
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Cool.  Glad I could help.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now