Consulting

Results 1 to 3 of 3

Thread: Macro OK. Script NOT OK.

  1. #1
    VBAX Newbie
    Joined
    Jul 2014
    Posts
    2
    Location

    Macro OK. Script NOT OK.

    I have a working macro (below): a certain type of email arrives and a rule directs it to a folder. I hand run a macro which extracts info from the body, creates a url, a launches in my default browser (Chrome). Does exactly as required.

    I've converted to a script (below). The rule directs to the folder, and then runs the script. The extract and create step works, but not the launch.

    I'm new to VBA programming so guess I've made a mistake/assumption somewhere?

    Macro
    ====
    Sub PostLog()
    Dim MyMail As Outlook.MailItem
    Dim Reg1 As RegExp
    Dim M1 As MatchCollection
    Dim M As Match
    Dim strAddress As String
    Dim objShell

    Set MyMail = Application.ActiveExplorer().Selection(1)

    Set Reg1 = New RegExp

    With Reg1
    .Pattern = "my pattern"
    .Global = False
    End With
    If Reg1.Test(MyMail.Body) Then
    Set M1 = Reg1.Execute(MyMail.Body)
    For Each M In M1
    strAddress = "my url" + Mid(M, 19, 26)
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run (strAddress)
    Next
    End If

    End Sub

    Script
    =====
    Sub PostLog(MyMail As Outlook.MailItem)
    Dim Reg1 As RegExp
    Dim M1 As MatchCollection
    Dim M As Match
    Dim strAddress As String
    Dim objShell

    Set Reg1 = New RegExp

    With Reg1
    .Pattern = "my pattern"
    .Global = False
    End With
    If Reg1.Test(MyMail.Body) Then
    Set M1 = Reg1.Execute(MyMail.Body)
    For Each M In M1
    strAddress = "my url" + Mid(M, 19, 26)
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run (strAddress)
    Next
    End If

    End Sub

  2. #2
    how is the script called?

    The extract and create step works
    how can you tell?

  3. #3
    VBAX Newbie
    Joined
    Jul 2014
    Posts
    2
    Location
    The script is called as "run a script" as the last task in a rule.

    I've MsgBox traced to display the values.

    I wondered if CreateObject is OK for a macro but not a script?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •