Hi Guys,
The following code opens up a dialog window before emails and attachments get saved down on the network. I want this to be automated so that no dialog save as window will open up and the emails and attachments will be saved down on the network automatically. Any help will be much appreciated .
The following code opens up a dialog window before emails and attachments get saved down on the network. I want this to be automated so that no dialog save as window will open up and the emails and attachments will be saved down on the network automatically. Any help will be much appreciated .
Code:
Public Sub MergeMailAndAttachsToPDF_New()
'Update by Extendoffice 2018/3/5
Dim xSelMails As MailItem
Dim xFSysObj As FileSystemObject
Dim xOverwriteBln As Boolean
Dim xLooper As Integer
Dim xEntryID As String
Dim xNameSpace As Outlook.NameSpace
Dim xMail As Outlook.MailItem
Dim xExt As String
Dim xSendEmailAddr, xCompanyDomain As String
Dim xWdApp As Word.Application
Dim xDoc, xNewDoc As Word.Document
Dim I As Integer
Dim xPDFSavePath As String
Dim xPath As String
Dim xFileArr() As String
Dim xExcel As Excel.Application
Dim xWb As Workbook
Dim xWs As Worksheet
Dim xTempDoc As Word.Document
Dim strFileName As String
On Error Resume Next
If (Outlook.ActiveExplorer.Selection.Count > 1) Or (Outlook.ActiveExplorer.Selection.Count = 0) Then
MsgBox "Please Select a email.", vbInformation + vbOKOnly
Exit Sub
End If
Set xSelMails = Outlook.ActiveExplorer.Selection.Item(1)
xEntryID = xSelMails.EntryID
Set xNameSpace = Application.GetNamespace("MAPI")
Set xMail = xNameSpace.GetItemFromID(xEntryID)
xSendEmailAddr = xMail.SenderEmailAddress
xCompanyDomain = Right(xSendEmailAddr, Len(xSendEmailAddr) - InStr(xSendEmailAddr, "@"))
xOverwriteBln = False
Set xExcel = New Excel.Application
xExcel.Visible = False
Set xWdApp = New Word.Application
xExcel.DisplayAlerts = False
strSaveFldr = GetPrivateProfileString32("U:\test.ini", "SaveFolder", "FolderName")
strFileName = MortANo & "-" & DocType_Col1 & "-" & email & "-" & Environ("Username")
xPDFSavePath = [COLOR="Red"]xExcel.Application.GetSaveAsFilename(InitialFileName:=strSaveFldr & strFileName, FileFilter:="PDF Files(*.pdf),*.pdf")[/COLOR]
If xPDFSavePath = "False" Then
xExcel.DisplayAlerts = True
xExcel.Quit
xWdApp.Quit
Exit Sub
End If
xPath = Left(xPDFSavePath, InStrRev(xPDFSavePath, "\"))
cPath = xPath & xCompanyDomain & "\"
yPath = cPath & Format(Now(), "yyyy") & "\"
mPath = yPath & Format(Now(), "MMMM") & "\"