Solved

Convert VBA from outlock to vb script

Posted on 2008-06-16
12
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 21796021
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
ID: 21796086
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
ID: 21796121
"Here ---> End Message"
Sorry, I don't see that anywhere in the code.  Can you give me a line number?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 2

Author Comment

by:team2005
ID: 21796163
Hi!

Sorry , my mistace

Next Message  ---> Line 19
0
 
LVL 76

Expert Comment

by:David Lee
ID: 21796208
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
ID: 21796231
Hi!

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

Strange....
0
 
LVL 76

Expert Comment

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

Author Comment

by:team2005
ID: 21796474
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
ID: 21796518
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
ID: 21796623
Hi!

YES, its working now.

Thank you so mutch for BIG help
0
 
LVL 2

Author Closing Comment

by:team2005
ID: 31467703
Thanks
0
 
LVL 76

Expert Comment

by:David Lee
ID: 21797987
Cool.  Glad I could help.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

690 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