Solved

VB.net Excel Add-in Convert Word file to pfd and email

Posted on 2014-04-05
2
517 Views
Last Modified: 2014-04-06
Hi

I have an Excel 2007 add-in that I have built in VB.net 2010.

What VB.net code would I use to convert a closed Word .dotx file to pdf

and email the pfd file via Outlook?
0
Comment
Question by:murbro
2 Comments
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 39980852
You can use Office Interop, but is is better to use a managed dll.

Here is some sample code to convert a file to pdf using Office Interop:

Imports Microsoft.Office.Interop

Dim MyApp As New Word.Application
Dim MyWordDoc As Word.Document = MyApp.Documents.Open("C:\Test\Test.docx")
MyWordDoc.SaveAs(FileLocation, Word.WdSaveFormat.wdFormatPDF)

Open in new window


This is a sample sub to send an attachment (from http://www.dreamincode.net/forums/topic/60975-office-automation/):
Try
	    Dim objOutlook As Outlook.Application
	    Dim objEmail As Outlook.MailItem
	 
	    objOutlook = CType(CreateObject("Outlook.Application"), Outlook.Application)
	    objEmail = objOutlook.CreateItem(Outlook.OlItemType.olMailItem)
	 
	    Dim body As String
	    'Gets First word in TextBox
	    Dim firstWord As String = System.Text.RegularExp<b></b>ressions.Regex.Match(txtContact.Text, "^\w+\b").Value
	 
	    body = "Hi " & firstWord & "," & vbCrLf & vbCrLf
	    body += "Please find attached purchase order number " & txtPONumber.Text & "." & vbCrLf & vbCrLf
	    body += "Please confirm lead time." & vbCrLf & vbCrLf
	    body += "Thanks and Best Regards," & vbCrLf & cmbBuyer.SelectedItem.ToString
	 
	    With objEmail
	        .Subject = "Purchase Order " & txtPONumber.Text
	        .To = txtEmail.Text
	        .Body = body
	        .Attachments.Add(PDFFile)
	        .Display(True)
	    End With
	Catch ex As Exception
	    MsgBox("Unable to generate automatic email. Please create the email manually.", MsgBoxStyle.Information, "Error!")
	End Try

Open in new window

0
 

Author Closing Comment

by:murbro
ID: 39980958
Great. Thanks very much
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

685 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