Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-04-05
2
Medium Priority
?
531 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:Murray Brown
[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
2 Comments
 
LVL 27

Accepted Solution

by:
MacroShadow earned 2000 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:Murray Brown
ID: 39980958
Great. Thanks very much
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

650 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