Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
posting this here cuz the outlook programing group is very inactive...
hopefully with how active you guys are you can help! I apologize in advance for posting an outlook vba question in an excel vba group.
I've got this loop that automatically detects for pdf file attachments in a selected range of email items, saves them to Temp so that I am able to then run a shell to print them. Since sometimes there ARENT pdf attachments, I want to only have the flag status change to complete if the e-mail has a pdf attachment. logically, where I have the flagstatus event occur in my loop makes sense to me, but it only changes the flagstatus for the first item in my selection. Here's to hoping someone smarter than me can figure out what's going on here. Public Sub SaveandPrintAttachments() Dim objOL As Outlook.Application Dim objMsg As Outlook.MailItem Dim objAttachments As Outlook.Attachments Dim objSelection As Outlook.Selection Dim i As Long Dim lngCount As Long Dim strFile As String Dim strFolderpath As String Dim strExePath As String ' Get the path to your My Documents folder strFolderpath = "c:\temp\" Set objOL = CreateObject("Outlook.Application") Set objSelection = objOL.ActiveExplorer.Selection ' Set the Attachment folder. (Folder must exist.) strFolderpath = strFolderpath For Each objMsg In objSelection Set objAttachments = objMsg.Attachments lngCount = objAttachments.Count If lngCount 0 Then For i = lngCount To 1 Step -1 strFile = objAttachments.Item(i).FileName If Right(strFile, 3) = "pdf" Then strFile = strFolderpath & strFile objAttachments.Item(i).SaveAsFile strFile 'use ShellExecute to open the file 'this may not work with zip extension if you use Compressed folders ShellExecute 0, "print", strFile, vbNullString, vbNullString, 0 objMsg.FlagStatus = olFlagComplete End If Next End If Next ExitSub: Set objAttachments = Nothing Set objMsg = Nothing Set objSelection = Nothing Set objOL = Nothing End Sub |
#2
|
|||
|
|||
cảm ơn bác chia sẻ
|
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
posting this here cuz the outlook programing group is very inactive...
Edit as follows to reset lngCount before looping the messages...
... For Each objMsg In objSelection Set objAttachments = objMsg.Attachments lngCount = 0 'reset lngCount = objAttachments.Count If lngCount 0 Then For i = lngCount To 1 Step -1 strFile = objAttachments.Item(i).FileName If Right(strFile, 3) = "pdf" Then strFile = strFolderpath & strFile objAttachments.Item(i).SaveAsFile strFile 'use ShellExecute to open the file 'this may not work with zip extension if you use Compressed folders ShellExecute 0, "print", strFile, vbNullString, vbNullString, 0 objMsg.FlagStatus = olFlagComplete End If Next End If Next ExitSub: Set objAttachments = Nothing Set objMsg = Nothing Set objSelection = Nothing Set objOL = Nothing End Sub -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#4
|
|||
|
|||
Website batdongsanquangninh.vn l* website h*ng đầu về quảng cáo, mua bán bất động sản tại Quảng Ninh, ch*nh thức đươc th*nh l*p v*o năm 2012. Lĩnh vực hoạt động ch*nh của công ty l* quảng cáo, tư vấn, môi giới, mua bán, cho thuê bất động sản. Trải qua nhiều năm hoạt động chúng tôi đã nỗ lực vượt qua mọi khó khăn để dần từng bước thay đổi được phương thức quảng cáo v* mua bán truyền thống của người dân th*nh phố giúp cho Người bán v* Người mua rễ d*ng thực hiện các giao dịch mua bán nh*, đất một cách minh bạch, nhanh chóng. Rút kinh nghiệm qua việc hoạt động nhiều năm và từ những ý kiến đóng góp của quý khách, trong thời gian tới chúng tôi sẽ nỗ lực hơn nưa nhằm phát triển Website có thêm những t*nh năng ưu việt, quảng bá rộng khắp hơn nữa giúp cho các giao dịch được tiến h*nh một cách nhanh chóng. Ra đời xuất phát từ trải nghiệm thực tế của ch*nh người sáng l*p ra Công ty với mong muốn giúp cho cộng đồng có được thông tin minh bạch mang lại giá trị lợi *ch tốt nhất cho khách h*ng. Đây ch*nh l* cơ sở nền tảng để công ty xây dựng phương châm kinh doanh với mong muốn mang đến sự chuyên nghiệp, uy t*n, niềm tin cho khách h*ng. Các dịch vụ ch*nh: - Đăng tin quảng cáo mua bán nh* đất - Đăng banner quảng cáo - Đăng b*i PR quảng bá sản phẩm, dịch vụ bất động sản - Tư vấn, mua bán bất động sản - Môi giới bất động sản - bán nh* quảng ninh - nha dat hạ long Mọi thông tin đóng góp, quý khách vui lòng liên hệ |
#5
|
|||
|
|||
Quote:
|
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
posting this here cuz the outlook programing group is very inactive...
Thank you for the advice, but unfortunately only my first selected e-mail item is updating the flag.
There are attachments in every selected e-mail, but I only want to 'do stuff' when there is a PDF attachment. I was able to figure out how to save/print the pdf via shell, but adding categories/flagstatuses isn't happening on each e-mail. On Tuesday, November 22, 2016 at 10:09:00 PM UTC-7, GS wrote: Edit as follows to reset lngCount before looping the messages... ... For Each objMsg In objSelection Set objAttachments = objMsg.Attachments lngCount = 0 'reset lngCount = objAttachments.Count If lngCount 0 Then For i = lngCount To 1 Step -1 strFile = objAttachments.Item(i).FileName If Right(strFile, 3) = "pdf" Then strFile = strFolderpath & strFile objAttachments.Item(i).SaveAsFile strFile 'use ShellExecute to open the file 'this may not work with zip extension if you use Compressed folders ShellExecute 0, "print", strFile, vbNullString, vbNullString, 0 objMsg.FlagStatus = olFlagComplete End If Next End If Next ExitSub: Set objAttachments = Nothing Set objMsg = Nothing Set objSelection = Nothing Set objOL = Nothing End Sub -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#7
|
|||
|
|||
Quote:
1 like cho cmt của huynh, các hạ tâm phục khẩu phục! |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
posting this here cuz the outlook programing group is very inactive...
There are attachments in every selected e-mail, but I only want to
'do stuff' when there is a PDF attachment. I was able to figure out how to save/print the pdf via shell, but adding categories/flagstatuses isn't happening on each e-mail. I'm not understanding why you feel a need to update any flags! Your code only processes PDF files and so why do you need to flag it? -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
posting this here cuz the outlook programing group is very inactive...
On Wednesday, November 23, 2016 at 10:52:53 AM UTC-7, GS wrote:
There are attachments in every selected e-mail, but I only want to 'do stuff' when there is a PDF attachment. I was able to figure out how to save/print the pdf via shell, but adding categories/flagstatuses isn't happening on each e-mail. I'm not understanding why you feel a need to update any flags! Your code only processes PDF files and so why do you need to flag it? -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion Thank you for helping me with this Garry! You've been very very helpful in the past. Not all e-mail items have a PDF attachment, and I'm only looking to print PDF attachments. If there is no pdf attachment, the flag would not be updated to complete thus identifying the item for futher work to be done. If there is a PDF attachment, I want to be able to identify it as having been printed with the Complete checkmark. Hope that helps clarify? |
#10
Posted to microsoft.public.excel.programming
|
|||
|
|||
posting this here cuz the outlook programing group is very inactive...
On Wednesday, November 23, 2016 at 10:52:53 AM UTC-7, GS wrote:
There are attachments in every selected e-mail, but I only want to 'do stuff' when there is a PDF attachment. I was able to figure out how to save/print the pdf via shell, but adding categories/flagstatuses isn't happening on each e-mail. I'm not understanding why you feel a need to update any flags! Your code only processes PDF files and so why do you need to flag it? -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion Thank you for helping me with this Garry! You've been very very helpful in the past. Not all e-mail items have a PDF attachment, and I'm only looking to print PDF attachments. If there is no pdf attachment, the flag would not be updated to complete thus identifying the item for futher work to be done. If there is a PDF attachment, I want to be able to identify it as having been printed with the Complete checkmark. Hope that helps clarify? Thanks for clarifying, Matthew! I don't use OE and so have no idea of its automation specifics. Makes sense now as to why you need to flag messages! So you need to add an 'If..Then' check for the flag setting and only process those not yet processed. You could simply expand your check for the filetype... If Right$(strFile, 3) = "pdf" And _ objMsg.FlagStatus < olFlagComplete Then ...where you need to set the value for olFlagComplete somewhere so that your code knows what it is. (I don't see where it's defined in your routine so I assume it's defined at module level; -otherwise it persists as zero!) -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#11
Posted to microsoft.public.excel.programming
|
|||
|
|||
posting this here cuz the outlook programing group is very inactive...
Hi Matthew,
Am Tue, 22 Nov 2016 15:05:38 -0800 (PST) schrieb Matthew Dyer: hopefully with how active you guys are you can help! I apologize in advance for posting an outlook vba question in an excel vba group. I've got this loop that automatically detects for pdf file attachments in a selected range of email items, saves them to Temp so that I am able to then run a shell to print them. Since sometimes there ARENT pdf attachments, I want to only have the flag status change to complete if the e-mail has a pdf attachment. logically, where I have the flagstatus event occur in my loop makes sense to me, but it only changes the flagstatus for the first item in my selection. Here's to hoping someone smarter than me can figure out what's going on here. you check that the attachments are pdf files and only pdf files will be stored and printed. Why do you want to flag? I woluld store the pdf files and read the file names into an array. When I am through I print all saved pdf files: Sub Test() Dim objOL As Outlook.Application Dim objNameSpace As Outlook.Namespace Dim objFolder As Outlook.MAPIFolder Dim objItems As Outlook.Items Dim objItem As Object Dim i As Integer, n As Integer Dim varFiles() As Variant Dim strFolderpath As String, FN As String Set objOL = CreateObject("Outlook.Application") Set objNameSpace = objOL.GetNamespace("MAPI") Set objFolder = objNameSpace.GetDefaultFolder(olFolderInbox) Set objItems = objFolder.Items strFolderpath = "c:\temp\" For Each objItem In objItems If objItem.Class = olMail Then For i = 1 To objItem.Attachments.Count If Right(objItem.Attachments(i).Filename, 4) = ".pdf" Then ReDim Preserve varFiles(n) FN = strFolderpath & objItem.Attachments(i).Filename objItem.Attachments(i).SaveAsFile FN varFiles(n) = FN n = n + 1 End If Next End If Next 'Print all PDF files For i = LBound(varFiles) To 1 ShellExecute 0, "print", varFiles(i), "", "", 0 Next End Sub Regards Claus B. -- Windows10 Office 2016 |
#12
|
|||
|
|||
Quote:
|
#13
|
|||
|
|||
Quote:
|
#14
|
|||
|
|||
Quote:
|
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
trouble posting tothis group | Excel Discussion (Misc queries) | |||
Set Up to Export Excel group list to Outlook Express | Excel Discussion (Misc queries) | |||
the owner of posting should be able to delete the posting | Excel Discussion (Misc queries) | |||
Please see posting on 05/04/05 does anyone know how to group post? | Excel Worksheet Functions | |||
Programing Outlook using Excel | Excel Programming |