Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default 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   Report Post  
Junior Member
 
Posts: 1
Default

cảm ơn bác chia sẻ
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default 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   Report Post  
Banned
 
Posts: 4
Default



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ệ
Địa chỉ : Nguyễn Văn Cừ - Hạ Long - Quảng NinhĐiện thoại : 0984.690.188Email :
  #5   Report Post  
Banned
 
Posts: 5
Default

Quote:
Originally Posted by Matthew Dyer View Post
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
Tôi vẫn biết cmt cuối cùng của tôi không thể được like nhiều như thằng cmt đầu tiên, v* nhục nhã hơn khi cái cmt cuối cùng của tôi không phải l* cmt cuối cùng, nhưng tôi vẫn tự h*o khi được sở hữu nó.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default 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   Report Post  
Banned
 
Posts: 5
Default

Quote:
Originally Posted by Matthew Dyer View Post
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
Vị huynh đ*i n*y vãi th*t. Facebook l* nơi anh h*o võ lâm ch*nh phái t* phái hội tụ, Bắc có Tiêu Phong, Nam có Mộ Dung, Đông có Ho*ng Đảo Chủ, Tây có Âu Dương Phong, thiết hỏi võ lâm được mấy người có cmt bá đạo như huynh? E rằng mấy vị chưởng môn Ngũ Nhạc Kiếm Phái hoặc th*m ch* l* Đông Phương Giaó Chủ của Hắc Mộc Nhai ở t*n Tây Nguyên đôi khi cũng phải cúi đầu trước cmt của huynh.
1 like cho cmt của huynh, các hạ tâm phục khẩu phục!
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,182
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default 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   Report Post  
Banned
 
Posts: 4
Default

Quote:
Originally Posted by Matthew Dyer View Post
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 = &quot;c:\temp\&quot; Set objOL = CreateObject(&quot;Outlook.Application&quot;) 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 &gt; 0 Then For i = lngCount To 1 Step -1 strFile = objAttachments.Item(i).FileName If Right(strFile, 3) = &quot;pdf&quot; Then strFile = strFolderpath &amp; 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, &quot;print&quot;, 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
It is in reality a great and helpful piece of info. I'm satisfied that you shared this helpful info with us. Please keep us informed like this. Thanks for sharing.
  #13   Report Post  
Banned
 
Posts: 4
Default

Quote:
Originally Posted by Matthew Dyer View Post
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 = &quot;c:\temp\&quot; Set objOL = CreateObject(&quot;Outlook.Application&quot;) 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 &gt; 0 Then For i = lngCount To 1 Step -1 strFile = objAttachments.Item(i).FileName If Right(strFile, 3) = &quot;pdf&quot; Then strFile = strFolderpath &amp; 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, &quot;print&quot;, 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
I'd constantly want to be update on new content on this site, saved to bookmarks!
  #14   Report Post  
Junior Member
 
Posts: 9
Default

Quote:
Originally Posted by Matthew Dyer View Post
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 = &quot;c:\temp\&quot; Set objOL = CreateObject(&quot;Outlook.Application&quot;) 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 &gt; 0 Then For i = lngCount To 1 Step -1 strFile = objAttachments.Item(i).FileName If Right(strFile, 3) = &quot;pdf&quot; Then strFile = strFolderpath &amp; 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, &quot;print&quot;, 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
b*i viết rất hay. up để bay xa nhé
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
trouble posting tothis group Clif McIrvin[_2_] Excel Discussion (Misc queries) 10 April 7th 10 06:11 PM
Set Up to Export Excel group list to Outlook Express Leanne Excel Discussion (Misc queries) 1 November 23rd 07 09:43 AM
the owner of posting should be able to delete the posting Mahendra Excel Discussion (Misc queries) 7 August 8th 05 07:21 PM
Please see posting on 05/04/05 does anyone know how to group post? sra Excel Worksheet Functions 0 May 5th 05 08:12 PM
Programing Outlook using Excel V. Roe Excel Programming 5 July 23rd 04 06:00 PM


All times are GMT +1. The time now is 01:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"