From: Tushar on 29 May 2010 10:40 I use Adobe 9 version. However I am not able to locate the printer driver. Can u guide me where it can be? Graham Mayor wrote: Without the appropriate driver to test, and Outlook as the e-mail app. 30-Jan-09 Without the appropriate driver to test, and Outlook as the e-mail app., something along the lines of the following might work if the driver creates pdf files with the same name as the document. If it saves them in the same folder as the documents you can simplify the pdfname lines to pdfName = Left(ActiveDocument.Fullname, Len(ActiveDocument.Fullname) - 3) pdfName = pdfName & "pdf" 'the name and path of the PDF Sub PDFAs Attachment() Dim sPrinter As String Dim bStarted As Boolean Dim oOutlookApp As Outlook.Application Dim oItem As Outlook.MailItem Dim pdfName As String sPrinter = ActivePrinter If Len(ActiveDocument.Path) = 0 Then 'Document has not been saved ActiveDocument.Save 'so save it End If pdfName = Left(ActiveDocument.name, Len(ActiveDocument.name) - 3) pdfName = "c:\pdfpath\" & pdfName & "pdf" 'the name and path of the PDF ActivePrinter = "PDF Driver Name" 'set the PDF driver name Application.PrintOut 'print to the PDF driver ActivePrinter = sPrinter 'restore the original printer On Error Resume Next 'see if Outlook is running and if so turn your attention there Set oOutlookApp = GetObject(, "Outlook.Application") If Err <> 0 Then 'Outlook isn't running 'So fire it up Set oOutlookApp = CreateObject("Outlook.Application") bStarted = True End If 'Open a new e-mail message Set oItem = oOutlookApp.CreateItem(olMailItem) With oItem 'and add the detail to it .To = "someone(a)somewhere.com" 'send to this address .Subject = "New subject" 'This is the message subject .Body = "See attached document" ' This is the message body text .Attachments.Add Source:=pdfName, Type:=olByValue .Send '.Display '********************************** 'If you want to view the message before it goes 'change the line above from .Send to .Display 'Otherwise the message is sent straight to the Outbox 'and if you have Outlook set to send mail immediately, 'it will simply be Sent 'with no obvious sign that Outlook has operated. 'Apart from the copy in the Outlook Sent folder '********************************** End With If bStarted Then 'If the macro started Outlook, stop it again. oOutlookApp.Quit End If 'Clean up Set oItem = Nothing Set oOutlookApp = Nothing End Sub fam.hougaard(a)gmail.com wrote: Previous Posts In This Thread: On Friday, January 30, 2009 8:03 AM Graham Mayor wrote: If the pdf driver is programmable from vba to define the name of the PDF file If the pdf driver is programmable from vba to define the name of the PDF file created by the driver, OR it automatically, without user interference, uses the name of the saved document to create a PDF with the same name, then it should be possible. Otherwise it is just as simple to attach the PDF to a mail message. Acrobat provides this function out of the box (at a price). -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<> fam.hougaard(a)gmail.com wrote: On Friday, January 30, 2009 9:39 AM Graham Mayor wrote: Without the appropriate driver to test, and Outlook as the e-mail app. Without the appropriate driver to test, and Outlook as the e-mail app., something along the lines of the following might work if the driver creates pdf files with the same name as the document. If it saves them in the same folder as the documents you can simplify the pdfname lines to pdfName = Left(ActiveDocument.Fullname, Len(ActiveDocument.Fullname) - 3) pdfName = pdfName & "pdf" 'the name and path of the PDF Sub PDFAs Attachment() Dim sPrinter As String Dim bStarted As Boolean Dim oOutlookApp As Outlook.Application Dim oItem As Outlook.MailItem Dim pdfName As String sPrinter = ActivePrinter If Len(ActiveDocument.Path) = 0 Then 'Document has not been saved ActiveDocument.Save 'so save it End If pdfName = Left(ActiveDocument.name, Len(ActiveDocument.name) - 3) pdfName = "c:\pdfpath\" & pdfName & "pdf" 'the name and path of the PDF ActivePrinter = "PDF Driver Name" 'set the PDF driver name Application.PrintOut 'print to the PDF driver ActivePrinter = sPrinter 'restore the original printer On Error Resume Next 'see if Outlook is running and if so turn your attention there Set oOutlookApp = GetObject(, "Outlook.Application") If Err <> 0 Then 'Outlook isn't running 'So fire it up Set oOutlookApp = CreateObject("Outlook.Application") bStarted = True End If 'Open a new e-mail message Set oItem = oOutlookApp.CreateItem(olMailItem) With oItem 'and add the detail to it .To = "someone(a)somewhere.com" 'send to this address .Subject = "New subject" 'This is the message subject .Body = "See attached document" ' This is the message body text .Attachments.Add Source:=pdfName, Type:=olByValue .Send '.Display '********************************** 'If you want to view the message before it goes 'change the line above from .Send to .Display 'Otherwise the message is sent straight to the Outbox 'and if you have Outlook set to send mail immediately, 'it will simply be Sent 'with no obvious sign that Outlook has operated. 'Apart from the copy in the Outlook Sent folder '********************************** End With If bStarted Then 'If the macro started Outlook, stop it again. oOutlookApp.Quit End If 'Clean up Set oItem = Nothing Set oOutlookApp = Nothing End Sub fam.hougaard(a)gmail.com wrote: On Saturday, January 31, 2009 2:31 AM Graham Mayor wrote: Sorry, you'll need to add a reference to Outlook's object library in vba tools Sorry, you'll need to add a reference to Outlook's object library in vba tools > references. I was forgetting that this is not checked by default. -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<> fam.hougaard(a)gmail.com wrote: On Saturday, January 31, 2009 2:32 AM Graham Mayor wrote: I am not sure how that happened. I am not sure how that happened. There should be no space in the macro name thus Sub PDFAsAttachment() -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<> fam.hougaard(a)gmail.com wrote: On Saturday, January 31, 2009 5:53 AM Graham Mayor wrote: Re: Email a Word document as PDF from within Word fam.hougaard(a)gmail.com wrote: As I said at the outset, the macro will only work if the driver is programmable or if the PDF driver saves the PDF without user interaction. You will have to ask that of the PDF creation software people. -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<> On Sunday, February 01, 2009 10:58 AM fam.hougaar wrote: Email a Word document as PDF from within Word Is it possible to write af VBA code that converts an open Word document to a PDF file using a pdf-converter (installed as a printer driver - its eDoc Printer) and attaches it to an email. And how? On Sunday, February 01, 2009 10:58 AM fam.hougaar wrote: Re: Email a Word document as PDF from within Word On 30 Jan., 14:03, "Graham Mayor" <gma...(a)REMOVETHISmvps.org> wrote: It generates a PDF file with the same name as the document. It does provide the option to attach the pdf to an email, but this is selected in then "print window": When i select to print to the PDF printer-driver a box opens where email attachment can be selected folowed by pressing a Save buttom. However i would like it all done with just selecting one menu item. On Sunday, February 01, 2009 10:58 AM fam.hougaar wrote: Re: Email a Word document as PDF from within Word Thanks I will try the code, but isnt this line wrong: - On Sunday, February 01, 2009 10:58 AM fam.hougaar wrote: Re: Email a Word document as PDF from within Word I get an error "User-defined type not defined" in this line: Dim oOutlookApp As Outlook.Application Does the code run OK with you? On Sunday, February 01, 2009 10:58 AM fam.hougaar wrote: Re: Email a Word document as PDF from within Word On 31 Jan., 08:32, "Graham Mayor" <gma...(a)REMOVETHISmvps.org> wrote: me Thanks Graham, that did the trick However now it stops at an Filesave As box (probebly from til PDF- driver) where it waits for the user to press Save and then it continues creating the email. I would lile there to be no other user- interaction but to send the mail. Have to figur out if the Save button kan be presses/activatet automatically. Any ideas?. On Saturday, February 07, 2009 2:38 PM fam.hougaar wrote: Just got back to my project.Your code dosnt attach the pdf file to the email. Just got back to my project. Your code dosnt attach the pdf file to the email. Any ideas? On Saturday, February 07, 2009 2:38 PM fam.hougaar wrote: Re: Email a Word document as PDF from within Word Figured it out - it was due to the location of the pdf was in another place ;-) Submitted via EggHeadCafe - Software Developer Portal of Choice WPF Report Engine, Part 4 http://www.eggheadcafe.com/tutorials/aspnet/5ac799db-385f-431a-8a45-8b37cb7f3186/wpf-report-engine-part-4.aspx
From: Graham Mayor on 29 May 2010 11:12 For Adobe Acrobat (full version not the reader) change the line ActivePrinter = "PDF Driver Name" 'set the PDF driver name to ActivePrinter = "Adobe PDF" -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<> <Tushar P> wrote in message news:201052910406tusharpatki(a)rediffmail.com... >I use Adobe 9 version. However I am not able to locate the printer driver. >Can u guide me where it can be? > > > > Graham Mayor wrote: > > Without the appropriate driver to test, and Outlook as the e-mail app. > 30-Jan-09 > > Without the appropriate driver to test, and Outlook as the e-mail app., > something along the lines of the following might work if the driver > creates > pdf files with the same name as the document. If it saves them in the same > folder as the documents you can simplify the pdfname lines to > > pdfName = Left(ActiveDocument.Fullname, Len(ActiveDocument.Fullname) - 3) > pdfName = pdfName & "pdf" 'the name and path of the PDF > > > > Sub PDFAs Attachment() > Dim sPrinter As String > Dim bStarted As Boolean > Dim oOutlookApp As Outlook.Application > Dim oItem As Outlook.MailItem > Dim pdfName As String > sPrinter = ActivePrinter > > If Len(ActiveDocument.Path) = 0 Then 'Document has not been saved > ActiveDocument.Save 'so save it > End If > > pdfName = Left(ActiveDocument.name, Len(ActiveDocument.name) - 3) > pdfName = "c:\pdfpath\" & pdfName & "pdf" 'the name and path of the PDF > ActivePrinter = "PDF Driver Name" 'set the PDF driver name > Application.PrintOut 'print to the PDF driver > ActivePrinter = sPrinter 'restore the original printer > On Error Resume Next > > 'see if Outlook is running and if so turn your attention there > Set oOutlookApp = GetObject(, "Outlook.Application") > If Err <> 0 Then 'Outlook isn't running > 'So fire it up > Set oOutlookApp = CreateObject("Outlook.Application") > bStarted = True > End If > 'Open a new e-mail message > Set oItem = oOutlookApp.CreateItem(olMailItem) > With oItem 'and add the detail to it > .To = "someone(a)somewhere.com" 'send to this address > .Subject = "New subject" 'This is the message subject > .Body = "See attached document" ' This is the message body text > .Attachments.Add Source:=pdfName, Type:=olByValue > .Send > '.Display > '********************************** > 'If you want to view the message before it goes > 'change the line above from .Send to .Display > 'Otherwise the message is sent straight to the Outbox > 'and if you have Outlook set to send mail immediately, > 'it will simply be Sent > 'with no obvious sign that Outlook has operated. > 'Apart from the copy in the Outlook Sent folder > '********************************** > End With > If bStarted Then 'If the macro started Outlook, stop it again. > oOutlookApp.Quit > End If > 'Clean up > Set oItem = Nothing > Set oOutlookApp = Nothing > End Sub > > > > > fam.hougaard(a)gmail.com wrote: > > Previous Posts In This Thread: > > On Friday, January 30, 2009 8:03 AM > Graham Mayor wrote: > > If the pdf driver is programmable from vba to define the name of the PDF > file > If the pdf driver is programmable from vba to define the name of the PDF > file created by the driver, OR > it automatically, without user interference, uses the name of the saved > document to create a PDF with the same name, then it should be possible. > Otherwise it is just as simple to attach the PDF to a mail message. > Acrobat provides this function out of the box (at a price). > > -- > <>>< ><<> ><<> <>>< ><<> <>>< <>><<> > Graham Mayor - Word MVP > > My web site www.gmayor.com > Word MVP web site http://word.mvps.org > <>>< ><<> ><<> <>>< ><<> <>>< <>><<> > > > fam.hougaard(a)gmail.com wrote: > > On Friday, January 30, 2009 9:39 AM > Graham Mayor wrote: > > Without the appropriate driver to test, and Outlook as the e-mail app. > Without the appropriate driver to test, and Outlook as the e-mail app., > something along the lines of the following might work if the driver > creates > pdf files with the same name as the document. If it saves them in the same > folder as the documents you can simplify the pdfname lines to > > pdfName = Left(ActiveDocument.Fullname, Len(ActiveDocument.Fullname) - 3) > pdfName = pdfName & "pdf" 'the name and path of the PDF > > > > Sub PDFAs Attachment() > Dim sPrinter As String > Dim bStarted As Boolean > Dim oOutlookApp As Outlook.Application > Dim oItem As Outlook.MailItem > Dim pdfName As String > sPrinter = ActivePrinter > > If Len(ActiveDocument.Path) = 0 Then 'Document has not been saved > ActiveDocument.Save 'so save it > End If > > pdfName = Left(ActiveDocument.name, Len(ActiveDocument.name) - 3) > pdfName = "c:\pdfpath\" & pdfName & "pdf" 'the name and path of the PDF > ActivePrinter = "PDF Driver Name" 'set the PDF driver name > Application.PrintOut 'print to the PDF driver > ActivePrinter = sPrinter 'restore the original printer > On Error Resume Next > > 'see if Outlook is running and if so turn your attention there > Set oOutlookApp = GetObject(, "Outlook.Application") > If Err <> 0 Then 'Outlook isn't running > 'So fire it up > Set oOutlookApp = CreateObject("Outlook.Application") > bStarted = True > End If > 'Open a new e-mail message > Set oItem = oOutlookApp.CreateItem(olMailItem) > With oItem 'and add the detail to it > .To = "someone(a)somewhere.com" 'send to this address > .Subject = "New subject" 'This is the message subject > .Body = "See attached document" ' This is the message body text > .Attachments.Add Source:=pdfName, Type:=olByValue > .Send > '.Display > '********************************** > 'If you want to view the message before it goes > 'change the line above from .Send to .Display > 'Otherwise the message is sent straight to the Outbox > 'and if you have Outlook set to send mail immediately, > 'it will simply be Sent > 'with no obvious sign that Outlook has operated. > 'Apart from the copy in the Outlook Sent folder > '********************************** > End With > If bStarted Then 'If the macro started Outlook, stop it again. > oOutlookApp.Quit > End If > 'Clean up > Set oItem = Nothing > Set oOutlookApp = Nothing > End Sub > > > > > fam.hougaard(a)gmail.com wrote: > > On Saturday, January 31, 2009 2:31 AM > Graham Mayor wrote: > > Sorry, you'll need to add a reference to Outlook's object library in vba > tools > Sorry, you'll need to add a reference to Outlook's object library in vba > tools > references. I was forgetting that this is not checked by default. > > -- > <>>< ><<> ><<> <>>< ><<> <>>< <>><<> > Graham Mayor - Word MVP > > My web site www.gmayor.com > Word MVP web site http://word.mvps.org > <>>< ><<> ><<> <>>< ><<> <>>< <>><<> > > > fam.hougaard(a)gmail.com wrote: > > On Saturday, January 31, 2009 2:32 AM > Graham Mayor wrote: > > I am not sure how that happened. > I am not sure how that happened. There should be no space in the macro > name > thus > > Sub PDFAsAttachment() > > -- > <>>< ><<> ><<> <>>< ><<> <>>< <>><<> > Graham Mayor - Word MVP > > My web site www.gmayor.com > Word MVP web site http://word.mvps.org > <>>< ><<> ><<> <>>< ><<> <>>< <>><<> > > > fam.hougaard(a)gmail.com wrote: > > On Saturday, January 31, 2009 5:53 AM > Graham Mayor wrote: > > Re: Email a Word document as PDF from within Word > fam.hougaard(a)gmail.com wrote: > > > As I said at the outset, the macro will only work if the driver is > programmable or if the PDF driver saves the PDF without user interaction. > You will have to ask that of the PDF creation software people. > > -- > <>>< ><<> ><<> <>>< ><<> <>>< <>><<> > Graham Mayor - Word MVP > > My web site www.gmayor.com > Word MVP web site http://word.mvps.org > <>>< ><<> ><<> <>>< ><<> <>>< <>><<> > > On Sunday, February 01, 2009 10:58 AM > fam.hougaar wrote: > > Email a Word document as PDF from within Word > Is it possible to write af VBA code that converts an open Word > document to a PDF file using a pdf-converter (installed as a printer > driver - its eDoc Printer) and attaches it to an email. > > And how? > > On Sunday, February 01, 2009 10:58 AM > fam.hougaar wrote: > > Re: Email a Word document as PDF from within Word > On 30 Jan., 14:03, "Graham Mayor" <gma...(a)REMOVETHISmvps.org> wrote: > > It generates a PDF file with the same name as the document. > > It does provide the option to attach the pdf to an email, but this is > selected in then "print window": > When i select to print to the PDF printer-driver a box opens where > email attachment can be selected folowed by pressing a Save buttom. > > However i would like it all done with just selecting one menu item. > > On Sunday, February 01, 2009 10:58 AM > fam.hougaar wrote: > > Re: Email a Word document as PDF from within Word > Thanks I will try the code, but isnt this line wrong: > > - > > On Sunday, February 01, 2009 10:58 AM > fam.hougaar wrote: > > Re: Email a Word document as PDF from within Word > I get an error "User-defined type not defined" in this line: > > Dim oOutlookApp As Outlook.Application > > Does the code run OK with you? > > On Sunday, February 01, 2009 10:58 AM > fam.hougaar wrote: > > Re: Email a Word document as PDF from within Word > On 31 Jan., 08:32, "Graham Mayor" <gma...(a)REMOVETHISmvps.org> wrote: > me > > Thanks Graham, that did the trick > > However now it stops at an Filesave As box (probebly from til PDF- > driver) where it waits for the user to press Save and then it > continues creating the email. I would lile there to be no other user- > interaction but to send the mail. Have to figur out if the Save button > kan be presses/activatet automatically. Any ideas?. > > On Saturday, February 07, 2009 2:38 PM > fam.hougaar wrote: > > Just got back to my project.Your code dosnt attach the pdf file to the > email. > Just got back to my project. > > Your code dosnt attach the pdf file to the email. > > Any ideas? > > On Saturday, February 07, 2009 2:38 PM > fam.hougaar wrote: > > Re: Email a Word document as PDF from within Word > Figured it out - it was due to the location of the pdf was in another > place ;-) > > > Submitted via EggHeadCafe - Software Developer Portal of Choice > WPF Report Engine, Part 4 > http://www.eggheadcafe.com/tutorials/aspnet/5ac799db-385f-431a-8a45-8b37cb7f3186/wpf-report-engine-part-4.aspx
|
Pages: 1 Prev: word 2003 vba - get current heading id Next: How do I compare dates in Word 2007? |