+ Reply to Thread
Results 1 to 9 of 9

command button 1 (save as pdf named the current time and date . then send by email

  1. #1
    Registered User
    Join Date
    02-27-2013
    Location
    KSA
    MS-Off Ver
    2011 MAC & Mac 2015
    Posts
    54

    command button 1 (save as pdf named the current time and date . then send by email

    hello everyone. this is my first post. and i need your help with the following



    first of all im a beginer in Excel VBA code . no idea what im doing . but i came with the following after long searching



    basically what i want to do is the following : i want to creat a command button and the order for that button is to save the file as pdf . the file name will be the current date and time then the same button have to send the file as attachment to Outlook . im using Excel 2010.

    im using the following code for sending . but it send only excel sheet as excel file:
    Please Login or Register  to view this content.

    can someone help me to combine both order under one button ?


    thank you alot

    i found similar articles here. but it didnt work . i need to copy and paste please.

    thank you

    regards,

    Hani
    Last edited by vlady; 02-27-2013 at 09:57 PM.

  2. #2
    Valued Forum Contributor Hawkeye16's Avatar
    Join Date
    02-27-2013
    Location
    Holland
    MS-Off Ver
    ├•┤ Pew Pew
    Posts
    441

    Re: command button 1 (save as pdf named the current time and date . then send by email

    You should use CODE tags as to adhere to the forum rules

    Please Login or Register  to view this content.
    Have you tried simply just putting the code from one into the other? If not you could set the active workbook to a workbook variable at the beginning and just activating the workbook in between. This would be if you sent via email and it did not reactivate excel automatically.

  3. #3
    Registered User
    Join Date
    02-27-2013
    Location
    KSA
    MS-Off Ver
    2011 MAC & Mac 2015
    Posts
    54

    Re: command button 1 (save as pdf named the current time and date . then send by email

    i tried that before . it didnt work . with that format. it will save as PDF file. but when it gets attached. it will attach the excel sheet format. XLSM or XLS . something like that. as if you are hitting save then send
    i need the PDF file to be sent

  4. #4
    Valued Forum Contributor Hawkeye16's Avatar
    Join Date
    02-27-2013
    Location
    Holland
    MS-Off Ver
    ├•┤ Pew Pew
    Posts
    441

    Re: command button 1 (save as pdf named the current time and date . then send by email

    I misunderstood what you meant. I am not sure how to do that solely in excel. Sorry.

  5. #5
    Registered User
    Join Date
    02-27-2013
    Location
    KSA
    MS-Off Ver
    2011 MAC & Mac 2015
    Posts
    54

    Re: command button 1 (save as pdf named the current time and date . then send by email

    i have been told that it can be done by code filepath strin or pathfil string. any idea whats that command do ?

  6. #6
    Registered User
    Join Date
    02-27-2013
    Location
    KSA
    MS-Off Ver
    2011 MAC & Mac 2015
    Posts
    54

    Re: command button 1 (save as pdf named the current time and date . then send by email

    ok .... i found this but i dont know what i have to change . ca someone help me. all i need is to copy and paste . lol


    Option Explicit

    'Note: The macro's in this module call the functions in the "FunctionsModule"
    'Be sure that you also copy the code from this module if you want to use it in your own workbook.

    Sub RDB_Workbook_To_PDF_And_Create_Mail()
    Dim FileName As String

    'Call the function with the correct arguments
    FileName = RDB_Create_PDF(ActiveWorkbook, "", True, False)

    'For a fixed file name and overwrite it each time you run the macro use
    'RDB_Create_PDF(ActiveWorkbook, "C:\Users\Ron\Test\YourPdfFile.pdf", True, True)

    If FileName <> "" Then
    RDB_Mail_PDF_Outlook FileName, "[email protected]", "This is the subject", _
    "See the attached PDF file with the last figures" _
    & vbNewLine & vbNewLine & "Regards Ron de bruin", False
    Else
    MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
    "Microsoft Add-in is not installed" & vbNewLine & _
    "You Canceled the GetSaveAsFilename dialog" & vbNewLine & _
    "The path to Save the file in arg 2 is not correct" & vbNewLine & _
    "You didn't want to overwrite the existing PDF if it exist"
    End If
    End Sub



    Sub RDB_Worksheet_Or_Worksheets_To_PDF_And_Create_Mail()
    Dim FileName As String

    If ActiveWindow.SelectedSheets.Count > 1 Then
    MsgBox "There is more then one sheet selected," & vbNewLine & _
    "be aware that every selected sheet will be published"
    End If

    'Call the function with the correct arguments
    'Tip: You can also use Sheets("Sheet3") instead of ActiveSheet in the code(sheet not have to be active then)
    FileName = RDB_Create_PDF(ActiveSheet, "", True, False)

    'For a fixed file name and overwrite it each time you run the macro use
    'RDB_Create_PDF(ActiveSheet, "C:\Users\Ron\Test\YourPdfFile.pdf", True, True)

    If FileName <> "" Then
    RDB_Mail_PDF_Outlook FileName, "[email protected]", "This is the subject", _
    "See the attached PDF file with the last figures" _
    & vbNewLine & vbNewLine & "Regards Ron de bruin", False
    Else
    MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
    "Microsoft Add-in is not installed" & vbNewLine & _
    "You Canceled the GetSaveAsFilename dialog" & vbNewLine & _
    "The path to Save the file in arg 2 is not correct" & vbNewLine & _
    "You didn't want to overwrite the existing PDF if it exist"
    End If
    End Sub



    Sub RDB_Selection_Range_To_PDF_And_Create_Mail()
    Dim FileName As String

    If ActiveWindow.SelectedSheets.Count > 1 Then
    MsgBox "There is more then one sheet selected," & vbNewLine & _
    "ungroup the sheets and try the macro again"
    Else
    'Call the function with the correct arguments


    'For a fixed range use this line
    FileName = RDB_Create_PDF(Range("A10:I15"), "", True, False)

    'For the selection use this line
    'FileName = RDB_Create_PDF(Selection, "", True, True)

    'For a fixed file name and overwrite it each time you run the macro use
    'RDB_Create_PDF(Selection, "C:\Users\Ron\Test\YourPdfFile.pdf", True, True)

    If FileName <> "" Then
    RDB_Mail_PDF_Outlook FileName, "[email protected]", "This is the subject", _
    "See the attached PDF file with the last figures" _
    & vbNewLine & vbNewLine & "Regards Ron de bruin", False
    Else
    MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
    "Microsoft Add-in is not installed" & vbNewLine & _
    "You Canceled the GetSaveAsFilename dialog" & vbNewLine & _
    "The path to Save the file in arg 2 is not correct" & vbNewLine & _
    "You didn't want to overwrite the existing PDF if it exist"
    End If
    End If
    End Sub

  7. #7
    Registered User
    Join Date
    02-27-2013
    Location
    KSA
    MS-Off Ver
    2011 MAC & Mac 2015
    Posts
    54

    Re: command button 1 (save as pdf named the current time and date . then send by email

    i want to have that macro in my excel sheet. but i want to change the method of save to ....
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "C:\Users\SAFA\Documents\SAFA Dispatch Handover Report " & _
    Format(Now, "dd mmm yy hh mm ") & ".pdf"



    then i want that PDF file to be send as mail. i found the code above. but i couldnt know how to combine them under one button

  8. #8
    Valued Forum Contributor
    Join Date
    11-15-2008
    Location
    ph
    MS-Off Ver
    2007/2010/2016
    Posts
    479

    Re: command button 1 (save as pdf named the current time and date . then send by email

    Hi -

    Use CODE tags in your post.

    Please Login or Register  to view this content.
    event

  9. #9
    Registered User
    Join Date
    02-27-2013
    Location
    KSA
    MS-Off Ver
    2011 MAC & Mac 2015
    Posts
    54

    Re: command button 1 (save as pdf named the current time and date . then send by email

    Event 21. you are the best !!!! thank you !!!oh my God!! it took me a week to get this , i can submit my deadline now ))))

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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