+ Reply to Thread
Results 1 to 17 of 17

send as pdf via outlook

  1. #1
    Forum Contributor
    Join Date
    08-18-2017
    Location
    india
    MS-Off Ver
    2010
    Posts
    490

    send as pdf via outlook

    Hey Guys,

    I was researching in internet and found this on internet, It does this:

    1. Save the ActiveSheet as PDF in Temporary Folder of the System
    2. Attach the File in Outlook New Email
    3. Send the Email
    4. Delete the PDF file from the Temp Folder.

    Please Login or Register  to view this content.


    Now,

    1) I want the file name to be (In temporary folder)

    filename1 = Range("C3").Text
    filename2 = Range("Q42").Text

    (In pdf format- only sheet1)

    2) Also i dont want the last part of the code which displays message box that mail has been sent.


    Is this possible?

    Can anyone please help me

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: send as pdf via outlook

    1) Your code deals with one file but you listed two files here. I am going to suggest that you add an argument to the Sub and then pass in the desired file name.

    Current Sub declaration:
    Please Login or Register  to view this content.
    Current code to set file name:
    Please Login or Register  to view this content.
    Current code that calls this Sub:
    Please Login or Register  to view this content.
    Revised Sub declaration:
    Please Login or Register  to view this content.
    Remove the lines of code shown above to set file name.

    Revised code that calls this Sub:
    Please Login or Register  to view this content.
    2)
    Just delete the line of code that displays the MsgBox.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    08-18-2017
    Location
    india
    MS-Off Ver
    2010
    Posts
    490

    Re: send as pdf via outlook

    Hey 6StringJazzer,

    Thank you so much for taking out time and helping me.

    I have updated the code but the macro isnt working for me.

    Maybe my temporary file path has an error?

    Could you please help me.


    Please Login or Register  to view this content.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: send as pdf via outlook

    You are not using Environ correctly. Environ takes one argument for an environment variable and returns the value of that variable. Your original code used "temp" which returns the default temp folder on your system. You replaced that with

    Please Login or Register  to view this content.
    which is meaningless. I think you want this:

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    08-18-2017
    Location
    india
    MS-Off Ver
    2010
    Posts
    490

    Re: send as pdf via outlook

    Hey 6StringJazzer,

    Thanks.

    I have replaced the code with the original which is :

    Please Login or Register  to view this content.
    However I get an error. I have attached the images below.
    Attached Images Attached Images

  6. #6
    Forum Contributor
    Join Date
    02-26-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    173

    Re: send as pdf via outlook

    Please Login or Register  to view this content.
    This returns a range. You are trying to use a range as a string. You probably want this:
    Please Login or Register  to view this content.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: send as pdf via outlook

    You did not make the changes quite as I specified.

    Somewhere outside of this Sub you have code that calls this Sub. It looks like this:
    Please Login or Register  to view this content.
    You have not provided your file or code so I have no idea where it is. To call it twice using the two cells you mentioned, you need to replace it with this:
    Please Login or Register  to view this content.
    Second, you have not changed the declaration of your sub.

    You need to go step by step through my post #2 and make each change. If you want more help then please attach your actual file. Images of code are not very useful.

    Quote Originally Posted by smpita View Post
    Please Login or Register  to view this content.
    This returns a range. You are trying to use a range as a string. You probably want this:
    Please Login or Register  to view this content.
    First, see my comment above. The code is simply in the wrong place, and no fix on these lines of code will work.

    Second, a range reference can be used as a string. VBA objects each have a default attribute that is assumed when the object reference is used where an expression is expected. The default attribute of Range is Value. That means that if you use

    Range("C3")

    it is exactly the same as using

    Range("C3").Value

    (This is not true if Range is on the right side of a Set statement.) So syntax is not the problem.
    Last edited by 6StringJazzer; 01-25-2018 at 03:59 PM.

  8. #8
    Forum Contributor
    Join Date
    02-26-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    173

    Re: send as pdf via outlook

    Quote Originally Posted by 6StringJazzer View Post
    The default attribute of Range is Value. That means that if you use

    Range("C3")

    it is exactly the same as using

    Range("C3").Value

    (This is not true if Range is on the right side of a Set statement.) So syntax is not the problem.
    The only return for the Range() is a range object. https://msdn.microsoft.com/en-us/vba...e-object-excel
    The only condition in which you can concatenate a string with an object is if you're not using the Explicit Option. Without this option being set, all variables are cast to variants unless explicitly declared. As variants, Excel capable of automagically correct these syntax errors.

    It's generally considered good coding practices to take control of your data typing by setting the Explicit Option. People have a habit of suggesting its usage. If OP or some other person tries to use this snippet with the Explicit Option, it will not work. It is not the same. The provided code doesn't make it clear whether OP is taking advantage of the Explicit Option. You are obviously knowledgable in VBA and a valued member of this community. As a point of individual growth, I'd suggest you turn on Option Explicit and see the difference. It is also helpful for catching typos in your variables. You can do this by adding the following code block to the top of any module.

    Note: It will only be enabled for that specific module.
    Please Login or Register  to view this content.
    Edit:

    I accidentally linked the wrong document. I provided the one to the Range object, not to the Range(). Here is the documentation for the Range(). https://msdn.microsoft.com/en-us/vba...property-excel
    Last edited by smpita; 01-25-2018 at 05:07 PM. Reason: Wrong doc

  9. #9
    Forum Contributor
    Join Date
    08-18-2017
    Location
    india
    MS-Off Ver
    2010
    Posts
    490

    Re: send as pdf via outlook

    Hey,

    I am attaching my sample file.

    All i want is to have a button in sheet "INVOICE" by which (macro code)

    * I get a mail in pdf format of the excel file.
    * The file name must be : "Range C3" & "Range Q2"
    Attached Files Attached Files
    Last edited by anilpatni1234; 01-26-2018 at 02:26 AM.

  10. #10
    Forum Contributor
    Join Date
    02-26-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    173

    Re: send as pdf via outlook

    Quote Originally Posted by 6StringJazzer View Post
    You did not make the changes quite as I specified.

    Somewhere outside of this Sub you have code that calls this Sub. It looks like this:
    Please Login or Register  to view this content.
    You have not provided your file or code so I have no idea where it is. To call it twice using the two cells you mentioned, you need to replace it with this:
    Please Login or Register  to view this content.
    Second, you have not changed the declaration of your sub.

    You need to go step by step through my post #2 and make each change.
    You need to implement the rest of the changes 6StringJazzer outlined for you. What I pointed out was a problem, but not the only issue. The biggest issue here is that you're trying to call a sub from within it self, as well as pass it arguments while it does not accept any.

  11. #11
    Forum Contributor
    Join Date
    02-26-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    173

    Re: send as pdf via outlook

    Like this. You need to call Email_ActiveSheet_Caller not Email_ActiveSheet_As_PDF.

    Please Login or Register  to view this content.

  12. #12
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: send as pdf via outlook

    Quote Originally Posted by anilpatni1234 View Post
    * The file name must be : "Range C3" & "Range Q2"
    This is not what you said in your first post:
    filename1 = Range("C3").Text
    filename2 = Range("Q42").Text
    I would be happy to directly modify your file but only if we get the description right first. If you want one file, things are very, very simple compared to the code I posted above.

  13. #13
    Forum Contributor
    Join Date
    08-18-2017
    Location
    india
    MS-Off Ver
    2010
    Posts
    490

    Re: send as pdf via outlook

    True. Hey 6StringJazzer I am really sorry for the confusion.

    I just want a pdf mailed to me and the name of the file must be Range C3 and Range Q42.

    A macro code will help.

  14. #14
    Forum Contributor
    Join Date
    08-18-2017
    Location
    india
    MS-Off Ver
    2010
    Posts
    490

    Re: send as pdf via outlook

    ANyone please help me

  15. #15
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: send as pdf via outlook

    Works fine for me.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  16. #16
    Forum Contributor
    Join Date
    08-18-2017
    Location
    india
    MS-Off Ver
    2010
    Posts
    490

    Re: send as pdf via outlook

    Hey Bakerman,

    As i said earlier, YOU ARE A LEGEND.

    Thank you so much.

  17. #17
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: send as pdf via outlook

    Glad to help and thanks for rep+.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Outlook 2010, send all emails from outlook outbox
    By joao1232 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-22-2016, 07:33 PM
  2. [SOLVED] Click to send outlook mail (outlook 2007 )
    By ks1102 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-07-2014, 02:54 AM
  3. [SOLVED] send sheet automatically via Outlook wihtout clicking on "send"
    By aucho in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-09-2013, 06:27 PM
  4. outlook redemtion macro cant send mail if outlook is not open ?
    By okl in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-03-2010, 07:35 AM
  5. How can I use Outlook express to send mail rather than Outlook by VBA code
    By new.microsoft.com in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-03-2005, 11:05 AM
  6. [SOLVED] How can I use Outlook express to send mail rather than Outlook by VBA code
    By new.microsoft.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-01-2005, 08:05 AM
  7. Send to Outlook 2000 not Outlook Express
    By Jimbo in forum Excel General
    Replies: 2
    Last Post: 01-04-2005, 05:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1