Solved

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

Posted on 2014-04-05
2
523 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 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:Murray Brown
ID: 39980958
Great. Thanks very much
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

696 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