Sure, No Problem.
Sub Export_as_PDF()
Dim objSession As MAPI.Session ' Local
Dim objMessage As Message ' local
Dim objRecip As Recipient
Dim NameVar As Variant
Dim NameVal As Variant, ccval As Variant, FullNameVal As Variant
Dim GendernameVar As Variant
Dim SectionVar As Variant
Dim ToLanIdVar As Variant
Dim DocName, NewName, DocPath As String
Dim Userid As String
Dim CCName As String
Dim aCCName() As String
Dim aBCCName() As String
Dim rs As New ADODB.Recordset
Dim sConnectString As String
Dim sSQL As String
Dim sDSN As String
Dim sServerName As String
Dim sUID As String
Dim sPWD As String
Dim aData As Variant
Dim X As Integer, NameIndex As Integer
Dim sDelim As String
Dim pdfApp As Acrobat.CAcroApp
Dim pdfDoc As Acrobat.CAcroPDDoc
Dim DocPathDate As String
Dim Sender As AddressEntry
Dim Lists As MAPI.AddressLists
Dim list As MAPI.AddressList
Dim entries As MAPI.AddressEntries
Dim filter As MAPI.AddressEntryFilter
Dim entry As MAPI.AddressEntry
'Dim SepVal As Variant
'Dim filtervar As Variant
'Dim filter, filterText As String
Dim TodaysDate As String
Dim n As Integer
Set pdfApp = CreateObject("AcroExch.App")
Set pdfDoc = CreateObject("AcroExch.PDDoc")
sDSN = "PROD"
sServerName = "SERVER_NAME"
sUID = "xxx"
sPWD = "xxxxx"
NameIndex = 1
TodaysDate = Format(Date, "MMDDYYYY")
'Pathing = "\\ATRMJBO2\DATA1\MISDATA\HR\PRINT\BUSOBJ\"
DocPath = "H:\MISDATA\HR\PRINT\BUSOBJ\Q106"
'DocPath = "Q:\MISDATA\HR\print\BUSOBJ\Q106"
'filterText = "v_section"
'filtervar = ActiveDocument.Evaluate("=<" & filterText & ">", boUniqueValues)
DocName = ActiveDocument.Name
NameVar = ActiveDocument.Evaluate("=<v_section>", BoAllValues)
'GendernameVar = ActiveDocument.Evaluate("=<GENDERNAME>", BoAllValues)
'FullNameVar = ActiveDocument.Evaluate("=<FULLNAME>", BoAllValues)
SectionVar = ActiveDocument.Evaluate("=<Section Code>", BoAllValues)
ToLanIdVar = ActiveDocument.Evaluate("=<Lan User Id>", BoAllValues) 'don't need this for Q106
'DocPath = "\\atrobj01\edrive\busobj\nobookmarks\Notification Reports"
DocPathDate = Format(Now, "mmm") & Year(Now)
For Each NameVal In NameVar
For n = 1 To ActiveDocument.Reports.Count
Call ActiveDocument.Reports(n).AddComplexFilter("v_section", "=<Section Code> = """ & _
NameVal & """")
ActiveDocument.Reports(n).ForceCompute
Next n
'Creating the directory if it doesn't exist ie: Jun2003
If Dir(DocPath & "\" & DocPathDate, vbDirectory) = "" Then
MkDir DocPath & "\" & DocPathDate
End If
NewName = DocPath & "\" & DocPathDate & "\" & NameVal 'for PathName\Filter.rep
ActiveDocument.ExportAsPDF (NewName) 'creates file on server
'The following lines of code opens the document and resaves it without the bookmarks
If pdfDoc.Open(NewName & ".PDF") Then 'if the document is opened successfully
pdfDoc.SetPageMode 1
Call pdfDoc.Save(1, NewName & ".PDF")
pdfDoc.Close
Else
MsgBox "Could not open PDF file " & NewName & ".PDF", vbCritical
End
End If
sSQL = "SELECT LAN_USER_ID FROM HR.PERSNOTF WHERE MEMO = 'TO' and Section = " & SectionVar(NameIndex) & _
" ORDER BY DECODE(ADMIN_CODE, 'AC','1','HS','2','AD','3','4')"
'sConnectString = "Data Source=" & sDSN & ";SERVER=" & sServerName & ";UID=" & sUID & ";PWD=" & sPWD & ";"
sConnectString = "Provider=MSDAORA;" & "Data Source=prod;" & "User ID=XX;" & "Password=XXXX;" & "database=prod;"
'open a recordset
rs.Open sSQL, sConnectString
ReDim aCCName(0) As String
Do Until rs.EOF
ReDim Preserve aCCName(UBound(aCCName) + 1) As String
aCCName(UBound(aCCName) - 1) = rs!LAN_USER_ID
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
'Doing a select to get the BCC names.
sSQL = "SELECT LAN_USER_ID FROM HR.HR_STAFF WHERE NAME LIKE 'BACHMAN, LORI%' " & _
"OR NAME LIKE 'CARTER, LINDA%' "
'sConnectString = "Data Source=" & sDSN & ";SERVER=" & sServerName & ";UID=" & sUID & ";PWD=" & sPWD & ";"
sConnectString = "Provider=MSDAORA;" & "Data Source=prod;" & "User ID=XX;" & "Password=XXXX;" & "database=prod;"
'open a recordset
rs.Open sSQL, sConnectString
ReDim aBCCName(0) As String
Do Until rs.EOF
ReDim Preserve aBCCName(UBound(aBCCName) + 1) As String
aBCCName(UBound(aBCCName) - 1) = rs!LAN_USER_ID
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
'Try sending out the e-mail here
Set objSession = CreateObject("MAPI.Session")
'Use a profile which exists on your Exchange Server as mailid.We created bo_admin for ours
objSession.Logon profileName:="Lori Bachman", ProfilePassword:="XXXX", newSession:=False, showDialog:=False
If objSession Is Nothing Then
Err.Raise 10, "MA MACRO", "must first log on; use Session->Logon"
Exit Sub
End If
Set objMessage = objSession.Outbox.Messages.Add
If objMessage Is Nothing Then
Err.Raise 11, "MA MACRO", "could not create a new message in the Outbox"
Exit Sub
End If
With objMessage
Set Lists = objSession.AddressLists
Set list = Lists.Item(1)
Set entries = list.AddressEntries 'Gets address entries
Set filter = entries.filter
filter.Name = "Jennifer Hill" 'Sending e-mail out for this person
Set entry = entries.GetFirst()
Set .Sender = entry
.Subject = "Quarterly Promotion Report"
.Text = "Attached is the quarterly professional promotion eligibility report for all attorneys, economists, and financial analysts." & Chr(13) & _
(Chr(13) + Chr(10)) & (Chr(13) + Chr(10)) & "Thanks," & Chr(13) & "Michele Garvey"
Set objAttach = .Attachments.Add ' add the attachment
If objAttach Is Nothing Then
Err.Raise 12, "MA MACRO", "Unable to create new Attachmentobject"
Exit Sub
End If
With objAttach
.Name = NameVal & ".pdf" 'this is the name of the report
.Source = DocPath & "\" & DocPathDate & "\" & NameVal & ".pdf"
End With
.Update 'update message to save attachment in MAPI system
Set objRecip = .Recipients.Add
With objRecip
objRecip.Name = ToLanIdVar(NameIndex) 'Substitute with individual mailid or groupname
objRecip.Type = CdoTo
objRecip.Resolve
End With
For X = 0 To UBound(aCCName) - 1
Set objRecip = .Recipients.Add
With objRecip
objRecip.Name = aCCName(X) 'Substitute with individual mailid or groupname
objRecip.Type = CdoCc
objRecip.Resolve
End With
.Update
Next X
For X = 0 To UBound(aBCCName) - 1
Set objRecip = .Recipients.Add
With objRecip
objRecip.Name = aBCCName(X) 'Substitute with individual mailid or groupname
objRecip.Type = CdoBcc
objRecip.Resolve
End With
.Update 'update message to save Bcc names in MAPI system
Next X
' .Send showDialog:=False
End With
'Kill DocPath & "\" & DocPathDate & "\" & NameVal & "-" & DocName & ".pdf"
objSession.Logoff
Set objSession = Nothing
Set objRecip = Nothing
Set objAttach = Nothing
Set objMessage = Nothing
NameIndex = NameIndex + 1
Next
For n = 1 To ActiveDocument.Reports.Count
Call ActiveReport.AddComplexFilter("NAME", "=<NAME> =<NAME>")
' To delete a Complex Filter, you set it equal to itself...
ActiveReport.ForceCompute
Next n
End Sub
bachman
(BOB member since 2002-09-24)