+ Reply to Thread
Results 1 to 4 of 4

Create pdf and label

  1. #1
    Registered User
    Join Date
    06-26-2014
    Location
    New Plymouth Taranaki
    MS-Off Ver
    2013
    Posts
    29

    Create pdf and label

    HI,
    I am using the following code to create a pdf from and excel sheet.
    I want the name of the cell to be the contents of D15.
    Haven't used macros for over a year and I am very rusty.
    [code]
    Sub AttachActiveSheetPDF()
    Dim IsCreated As Boolean
    Dim i As Long
    Dim PdfFile As String, Title As String
    Dim OutlApp As Object

    ' Not sure for what the Title is
    Title = Range("A1")

    ' Define PDF filename

    PdfFile = ActiveWorkbook.FullName

    i = InStrRev(PdfFile, ".")
    If i > 1 Then PdfFile = Left(PdfFile, i - 1)
    PdfFile = PdfFile & "_" & ActiveSheet.Name & ".pdf"

    ' Export activesheet as PDF
    With ActiveSheet
    .ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    End With

    ' Use already open Outlook if possible
    On Error Resume Next
    Set OutlApp = GetObject(, "Outlook.Application")
    If Err Then
    Set OutlApp = CreateObject("Outlook.Application")
    IsCreated = True
    End If
    OutlApp.Visible = True
    On Error GoTo 0

    ' Prepare e-mail with PDF attachment
    With OutlApp.CreateItem(0)

    ' Prepare e-mail
    .Subject = Title
    .To = "[email protected]"
    .Body = "Hi," & vbLf & vbLf _
    & "The report is attached in PDF format. Can you please contact me for assistance." & vbLf & vbLf _
    & "Regards," & vbLf _
    & Application.UserName & vbLf & vbLf
    .Attachments.Add PdfFile

    ' Try to send
    On Error Resume Next
    .Send
    Application.Visible = True
    If Err Then
    MsgBox "E-mail was not sent", vbExclamation
    Else
    MsgBox "E-mail successfully sent", vbInformation
    End If
    On Error GoTo 0

    End With

    ' Delete PDF file
    Kill PdfFile

    ' Quit Outlook if it was created by this code
    If IsCreated Then OutlApp.Quit

    ' Release the memory of object variable
    Set OutlApp = Nothing

    End Sub
    [code/]

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Create pdf and label

    You can edit your original post to add code tags.

    AA CodeTags.jpg

  3. #3
    Forum Contributor IonutC's Avatar
    Join Date
    01-28-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    Office 2019
    Posts
    486

    Re: Create pdf and label

    HI,

    You want to name the pdf with the info from the cell D15?
    Please consider:
    Be polite. Thank those who have helped you.
    Click the star icon in the lower left part of the contributor's post and add Reputation. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .
    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Posting code between tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

  4. #4
    Registered User
    Join Date
    06-26-2014
    Location
    New Plymouth Taranaki
    MS-Off Ver
    2013
    Posts
    29

    Re: Create pdf and label

    Sorry for slow response.
    Yes, want to label document according to what they put into D15

+ 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. VBA create label with slideindex
    By bentod in forum PowerPoint Programing
    Replies: 3
    Last Post: 01-28-2019, 03:50 AM
  2. Create Label and print with excel
    By mazan2010 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-29-2016, 08:55 AM
  3. With a move label macro, prevent label from moving onto another label
    By SocratesJC in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-09-2014, 12:34 AM
  4. Create a Triangle in a label
    By frankish in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-29-2012, 08:03 AM
  5. create a sub label
    By skitols in forum Excel General
    Replies: 1
    Last Post: 05-28-2009, 12:18 PM
  6. How can I create a label over a small chart?
    By Linds in forum Excel General
    Replies: 2
    Last Post: 11-07-2005, 07:36 PM
  7. How do I create a column label in Excel?
    By Annette in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 02-21-2005, 03:06 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