Results 1 to 9 of 9

Create pdf from excel with specific range and today's date data

Threaded View

  1. #1
    Registered User
    Join Date
    11-21-2013
    Location
    Europe
    MS-Off Ver
    2016
    Posts
    7

    Create pdf from excel with specific range and today's date data

    He there,

    Can somebady help me to change this vba or create new one. I want to create daily report with specific range and select data from colummn based on todays date.
    I attached image of my schedule.
    This is my vba to create monthly report.

    Sub Saveaspdfandsend()
    Dim xSht As Worksheet
    Dim xFileDlg As FileDialog
    Dim xFolder As String
    Dim xYesorNo As Integer
    Dim xOutlookObj As Object
    Dim xEmailObj As Object
    Dim xUsedRng As Range
    
    Set year = ActiveSheet.Range("Q3")
    Set xSht = ActiveSheet
    Set xFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
     
    If xFileDlg.Show = True Then
       xFolder = xFileDlg.SelectedItems(1)
    Else
       MsgBox "Select folder to save PDF file." & vbCrLf & vbCrLf & "OK.", vbCritical, "Select location"
       Exit Sub
    End If
    xFolder = xFolder + "" + "Schedule " + xSht.Name + " " & Year & ".pdf"
     
    'Check if file already exist
    If Len(Dir(xFolder)) > 0 Then
        xYesorNo = MsgBox(xFolder & " Exist." & vbCrLf & vbCrLf & "Do you want to save with this number?", _
                          vbYesNo + vbQuestion, "File with this name exist")
        On Error Resume Next
        If xYesorNo = vbYes Then
            Kill xFolder
        Else
            MsgBox "File not saved." _
                        & vbCrLf & vbCrLf & "Ok.", vbCritical, "Exit"
            Exit Sub
        End If
        If Err.Number <> 0 Then
            MsgBox "Cant delete file. Check if file with same name is open." _
                        & vbCrLf & vbCrLf & "OK.", vbCritical, "Can't delete this file."
            Exit Sub
        End If
    End If
     
    Set xUsedRng = xSht.UsedRange
    If Application.WorksheetFunction.CountA(xUsedRng.Cells) <> 0 Then
        'Save as PDF file
        xSht.ExportAsFixedFormat Type:=xlTypePDF, Filename:=xFolder, Quality:=xlQualityStandard
         
        'Create Outlook email
        Set xOutlookObj = CreateObject("Outlook.Application")
        Set xEmailObj = xOutlookObj.CreateItem(0)
        With xEmailObj
            .Display
            .To = ""
            .Cc = ""
            .Subject = "Schedule " + xSht.Name + " " & Year & ", Data: " & Format(Date, "dd/mm/yyyy")
            .Attachments.Add xFolder
            .HTMLbody = "Test, " & "<br>" & " " & "<br>" & " Find atached " & xSht.Name & " " & Viti & "." & "<br>" & "<br>" & "BS,"
            If DisplayEmail = False Then
                '.Send
            End If
        End With
    Else
      MsgBox "Empty Worksheet."
      Exit Sub
    End If
    Administrator's note: Please take the time to review our rules. There aren't many, and they are all important. Our guidelines recommend code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Attached Images Attached Images
    Last edited by 6StringJazzer; 08-10-2024 at 10:54 AM. Reason: please use code tags

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How to fetch data according to today from a date range
    By akshay6s in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-28-2020, 12:48 AM
  2. Establish range for # of days a case has been open via create date and today's date
    By excelingtoexcel in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-06-2020, 11:54 AM
  3. [SOLVED] trying VBA code to get specific data for unique IDs on specific date from date range
    By Roshan.Shakya in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-21-2019, 06:16 AM
  4. Replies: 2
    Last Post: 12-31-2012, 12:47 PM
  5. [SOLVED] VBA to copy specific data from one workbook to another based on today's date?
    By hiprhit in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-09-2012, 02:21 PM
  6. Formula to search for today's date and return range of data
    By paramore in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-15-2012, 02:17 PM
  7. create today date line in excel gantt chart
    By omneo in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 07-13-2010, 10:25 AM

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