VBA Adding a prefix

JustynHart

New Member
Joined
Oct 30, 2017
Messages
3
Hi

i have written a code that adds a pdf to an email and names the pdf a value from a certain column in a cell and for some reason it is adding a " before the name when there isn't one

any help??
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Sub EmailPDF()


Dim strData As String
Dim ola As Outlook.Application
Dim maiMessage As Outlook.MailItem


Dim strSiteName As String


strSiteName = Tables(1).Cell(1, 2).Range.Text
strUserName = Application.UserName


strData = "D:" & "Kiosk Request Form - " & strSiteName & ".pdf"


'Creates a PDF and stores it locally


ActiveDocument.ExportAsFixedFormat OutputFileName:= _
strData, ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentWithMarkup, IncludeDocProps:=False, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False


On Error Resume Next


'Start Outlook if it isn't running


Set oOutlookApp = GetObject("Outlook.Application")


If Err <> 0 Then

Set oOutlookApp = CreateObject("Outlook.Application")


End If


'Create a new message


Set oItem = oOutlookApp.CreateItem(olMailItem)

oItem.Subject = "Kiosk Request Form - "
oItem.To = "mark@industrialgrp.co.uk"


oItem.HTMLBody = "<html><style> p { font-family: Arial; font-size: 12; }</style>******><p>Please find attached an initial kiosk request form for " & strSiteName & ".</p><p>Any queries, please let me know</p><p>Kind regards,</P><p>" & strUserName & "</body></html>"


oItem.Display




'Add attachment


oItem.Attachments.Add strData


'Create a file system object to delete temporary file


Set fs = CreateObject("Scripting.FileSystemObject")


fs.deletefile strData


End Sub


Private Sub CommandButton1_Click()


Call EmailPDF


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top