none
attaching a file in custom outlook form RRS feed

  • Question

  • outlook 2010, custom Form.

    Added Text fields and 1 button.
    I can access field values and save those values as a csv file.

    How can I attach that said just created csv file to the current form so I can send it via email?

    Sub cmdMakeCSV_Click()
    set dataForm = item.getInspector.ModifiedFormPages("Message") 'current form
    set field1 = dataForm.Controls ("txtField1") 'just this one value for this post
    call WriteFile( field1) ' writes the value to a csv file.
    : ? How to attach
    End Sub

    also..for every example I can find for attaching a file to a email, it requires declaring something.
    But If I try to DIM anything in the button code..i get errors...

    Even in I try:
    Sub cmdMakeCSV_Click()
    Dim varX as string //  ERROR HERE !
    set dataForm = item.getInspector.ModifiedFormPages("Message") 'current form
    set field1 = dataForm.Controls ("txtField1") 'just this one value for this post
    call WriteFile( field1) ' writes the value to a csv file.
    End Sub

    So how can I attach the file? 

    Brett


    • Edited by bflagg Sunday, September 10, 2017 3:29 AM
    Friday, September 8, 2017 4:00 PM

Answers

  • Hi bflagg,

    Please try below code.

    Function Commandbutton1_click()
    
    filepath="C:\Users\Administrator\Desktop\Book1.csv"
    
    item.Attachments.Add  filepath
    
    End Function

    Or you could also use this code.

    Function Commandbutton1_click()
    
    filepath="C:\Users\Administrator\Desktop\Book1.csv"
    
    set wordE=item.getinspector.wordeditor
    
    wordE.application.selection.InsertFile (filepath)
    
    End Function

    Best Regards,

    Terry

    • Marked as answer by bflagg Monday, September 11, 2017 6:40 PM
    Monday, September 11, 2017 8:33 AM

All replies

  • Hi bflagg,

    Please try below code.

    Function Commandbutton1_click()
    
    filepath="C:\Users\Administrator\Desktop\Book1.csv"
    
    item.Attachments.Add  filepath
    
    End Function

    Or you could also use this code.

    Function Commandbutton1_click()
    
    filepath="C:\Users\Administrator\Desktop\Book1.csv"
    
    set wordE=item.getinspector.wordeditor
    
    wordE.application.selection.InsertFile (filepath)
    
    End Function

    Best Regards,

    Terry

    • Marked as answer by bflagg Monday, September 11, 2017 6:40 PM
    Monday, September 11, 2017 8:33 AM
  • first one worked like a charm... Thank you.
    I'm new at outlook forms... thanks again





    • Edited by bflagg Monday, September 11, 2017 9:38 PM
    Monday, September 11, 2017 6:43 PM