Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 27 of 27

Thread: Solved: Outlook Body Text to Text File, Scripting and Guard Issues

  1. #21
    VBAX Regular
    Joined
    May 2007
    Posts
    87
    Location
    SMS was just an idea because I could send it from my standard mobile phone with the inclusive texting, rather than the dang.berry or XDA. But I suppose there's a limited amount of actions that could be performed from that, the phone couldn't receive a PDF, so no point.

    Time taken to run the PDF creation Trail file varies (depends on whether it's the first time ProE has been run after boot up, background processes, etc), and then it seems to run in the background, so I'm not sure it will trigger any kind of return, but I'll give it a go.

    -AS

  2. #22
    VBAX Regular
    Joined
    May 2007
    Posts
    87
    Location
    Matt,

    I've hit another (minor) problem. Currently the program excerpt above will save a text file, to all intents and purposes identical to the original text file, but if it is sent in any format other than "Plain Text" it'll trip over in ProE.

    The two files look identical, but one is using spaces with a Hex-Dec code of "20" and one is using spaces with a Hex-Dec code of "A0".

    Any ideas on how to amend the function above so that it will save as a Text File from "Plain Text" (suspect the difference in spaces is due to the HTML or Rich Text being used)?

    Cheers,

    -Andy.

  3. #23
    VBAX Regular
    Joined
    May 2007
    Posts
    87
    Location
    Currently, pretty it ain't, but it's alive!

    I've got a very hairy routine for a delay (need to do something like:

    Do Until Exist = "c:\output.pdf"
    loop
    -THAT'S NOT REAL CODE-

    Anyone know any way of locking Outlook into a loop until an output file exists on a local hard drive?


    But it now runs software on my PC as driven by a SPV M3100 PDAPhone.

    And sends an email out with a PDF generated by the ProE Trail file.

    -AS

  4. #24
    VBAX Regular
    Joined
    May 2007
    Posts
    87
    Location
    OK, that wasn't real code, to see if a file existed which I was generating.

    As previously mentioned ProE can take a while to churn out a PDF file, so I have to wait until this is done. I have used a time delay to do this:
    [vba]
    (in main sub)
    fnWait(120)
    (at end of main sub)

    Public Function fnWait(intNrOfSeconds As Integer)
    Dim varStart As Variant
    varStart = Timer
    Do While Timer < varStart + intNrOfSeconds
    Loop
    End Function
    [/vba]

    This was unfortunate, as I had to leave the Outlook Frozen in sleep mode for a long enough period that it would definately have the PDF generated.

    I now use this short line of code to make sure the file exists:
    [VBA]
    Dim PDFname As String

    PDFname = "C:\ProE\stell_ga.pdf"

    Do
    Loop Until Dir(PDFname, vbNormal) <> ""

    item.Attachments.Add (PDFname)
    item.Attachments.Add ("C:\ProE\stl_param.txt")

    [/VBA]

    It hits a Do Loop and stays there until the DIR command finds something matching the filename of the PDF that ProE is generating.

    Then it will email me the results. I'm sorry but this code is still incomplete, as I'm still in there and it's very messy, but I thought this method of waiting until a file has been generated would help someone.

    It might be better to have a ten second pause in the routine so the disc interface card isn't constently interrogating the same directory whilst you're trying to write a PDF to it, this could be done by combining the two routines.

    -AS

  5. #25
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Re: different types of spaces
    I was going to say use .Body instead of .HTMLBody, but it looks like you already use .Body. What you could do is replace the "bad" spaces with the normal ones:[vba]'vBody = Item.Body
    vBody = Replace(Item.Body, Chr(160), Chr(32))[/vba]


    Instead of using the Wait method like you're doing (even if you do use that, put "DoEvents" in the loop, or call the Sleep API), what you could do is use Wscript.Shell's Run method (see post #20 above), and use True in the WaitOnReturn to wait for the called command to complete.
    Matt

  6. #26
    VBAX Regular
    Joined
    May 2007
    Posts
    87
    Location
    Nice use of replace, it works, thanks.

    Overall system works, if I only do one set of parameters each time (until I return to my desk)

    I've got a little algorythm I'm working on for file management, then I should be ready to run.

    I'm tempted to even splash out some of the IT budget on a cheap PC (low spec, not even with a CAD - spec graphics card) and have it running 24/7 on that.......

    -AS

  7. #27
    VBAX Regular
    Joined
    May 2007
    Posts
    87
    Location
    For what it's worth, full coded examples.

    Email addresses, Paths, and Activation words have been changed to protect the innocent, for example where I say P3 is actually ProE3.....

    .....(Dan Ackroyd Joke, sorry!)

    [vba]
    Option Explicit
    Dim WithEvents vInbox As Items
    Private Sub Application_Startup()
    Set vInbox = Application.Session.GetDefaultFolder(olFolderInbox).Items
    Call CheckInbox
    End Sub
    Private Sub Application_NewMail()
    If vInbox Is Nothing Then
    Set vInbox = Application.Session.GetDefaultFolder(olFolderInbox).Items
    Call CheckInbox
    End If
    End Sub
    Sub filepause(attachname As String)
    Dim varStrt As Variant
    Do
    varStrt = Timer
    Do While Timer < varStrt + 10
    Loop
    Loop Until Dir(attachname, vbNormal) <> ""
    End Sub
    Sub SendAMessage(ByVal toname As String, attach1 As String, verint As Integer)
    Dim ns As NameSpace, attach2 As String, msg As MailItem
    ' Set up the namespace
    Set ns = ThisOutlookSession.Session

    attach2 = "C:\P3\files\" & verint & "_swell_ga.pdf"

    Call filepause(attach2)

    Set msg = Application.CreateItem(olMailItem)
    With msg
    .Recipients.Add "id2m@as.com"
    .Recipients.Add toname
    .Subject = "Your AutoGen Drawing"
    .Body = "This is your autogenerated drawing" & vbCrLf & "It's saved as file " & verint & vbCrLf & "I hope this is what you wanted....." & vbCrLf & "-AutoGen by id2m"
    .Attachments.Add (attach1)
    .Attachments.Add (attach2)
    .Send
    End With
    End Sub
    Function findversion(pathstring As String, filestring As String, verint As Integer)
    Dim vPath As String
    If Dir(pathstring & verint & filestring, vbNormal) <> "" Then
    Do
    verint = verint + 1
    vPath = pathstring & verint & filestring
    Loop Until Dir(vPath, vbNormal) = ""
    End If
    findversion = verint
    End Function

    Public Function fnWait(intNrOfSeconds As Integer)
    Dim varStart As Variant
    varStart = Timer
    Do While Timer < varStart + intNrOfSeconds
    Loop
    End Function
    Private Sub Application_Quit()
    Set vInbox = Nothing
    End Sub
    Function CheckInbox() As Boolean
    Dim vItems As Object, vItem As Object
    Set vItems = Application.Session.GetDefaultFolder(olFolderInbox).Items
    For Each vItem In vItems
    If TypeName(vItem) = "MailItem" Then
    If vItem.UnRead = True Then
    Call vInbox_ItemAdd(vItem)
    End If
    End If
    Next
    Set vItem = Nothing
    Set vItems = Nothing
    End Function
    Sub filerewriter(pthstg As String, verint As Integer, flnm As String)
    Dim VFF As Long, vNIStep As String, vOIStep As String, vBody As String, vIStep As String
    vNIStep = pthstg & verint & "_" & flnm
    vOIStep = pthstg & flnm

    VFF = FreeFile
    Open vOIStep For Binary As #VFF
    vBody = Space$(LOF(VFF))
    Get #VFF, , vBody
    Close #VFF
    vIStep = Replace(vBody, "1001", verint)
    Open vNIStep For Output As #VFF
    Print #VFF, vIStep
    Close #VFF

    End Sub
    Private Sub vInbox_ItemAdd(ByVal Item As Object)
    Dim pathstring As String, versionint As Integer, VFF As Long, vParam As String
    Dim vNIStep As String, vFlnm As String, PDFname As String, vBody As String

    If TypeName(Item) <> "MailItem" Then Exit Sub
    If Item.Subject <> "AutoOut" Then Exit Sub

    pathstring = "C:\P3\files\"
    vFlnm = "intereps.txt"
    ' findversion function call! Then Rewrite Trail Files!
    versionint = findversion(pathstring, "_swell_param.txt", 1000)
    Call filerewriter(pathstring, versionint, vFlnm)
    vParam = pathstring & versionint & "_swell_param.txt"
    vNIStep = pathstring & versionint & "_" & vFlnm
    Item.BodyFormat = olFormatPlain
    vBody = Replace(Item.Body, Chr(160), Chr(32))
    VFF = FreeFile
    Open vParam For Output As #VFF
    Print #VFF, vBody
    Close #VFF
    Item.UnRead = False 'Mark As Read
    ChDir pathstring
    ' needs a -If Exist- clause, can't be bothered though
    ' Shell "del trail*.*", vbNormalNoFocus
    Shell "C:\P3\proe.exe -g:no_graphics " & vNIStep, vbNormalFocus
    '-g:no_graphics makes ProE run faster (if no operator is required) as there is no graphics calculations.

    Call SendAMessage(Item.SenderEmailAddress, vParam, versionint)

    End Sub
    [/vba]
    Thanks for all the help I've had with this one.

    Remember you need to write a trail file and save it somewhere appropriate and have it modify a model to suit.

    I have changed a few of the names etc. as I entered this onto the internet, simply to suppliment security, but I might not have changed the file names or paths consistantly, so be aware there might be a few minor issues that need ironing out if you wish to use this program in a cut and paste way.

    Might benefit from Global Variables too.

    Now I'm in the mood for using a free download of SolidEdge 2D to a similar effect. Please see my next posting for helping me with that.

    Thanks once again,

    -Andy

    macro <at> andysouthern <dot> com

Posting Permissions

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