Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.scripting.vbscript > #12274 > unrolled thread

VBScript to get most recent subject headings from specific (not inbox) folder

Started byDan Campbell <dcwhatthe@gmail.com>
First post2020-05-27 17:25 -0700
Last post2020-05-28 14:02 -0700
Articles 7 — 4 participants

Back to article view | Back to microsoft.public.scripting.vbscript


Contents

  VBScript to get most recent subject headings from specific (not inbox) folder Dan Campbell <dcwhatthe@gmail.com> - 2020-05-27 17:25 -0700
    Re: VBScript to get most recent subject headings from specific (not inbox) folder "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-05-28 12:48 +0200
      Re: VBScript to get most recent subject headings from specific (not inbox) folder "Mayayana" <mayayana@invalid.nospam> - 2020-05-28 08:13 -0400
      Re: VBScript to get most recent subject headings from specific (not inbox) folder Dan Campbell <dcwhatthe@gmail.com> - 2020-05-28 06:08 -0700
        Re: VBScript to get most recent subject headings from specific (not inbox) folder "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-05-28 18:07 +0200
    Re: VBScript to get most recent subject headings from specific (not inbox) folder JJ <jj4public@vfemail.net> - 2020-05-28 20:14 +0700
      Re: VBScript to get most recent subject headings from specific (not inbox) folder Dan Campbell <dcwhatthe@gmail.com> - 2020-05-28 14:02 -0700

#12274 — VBScript to get most recent subject headings from specific (not inbox) folder

FromDan Campbell <dcwhatthe@gmail.com>
Date2020-05-27 17:25 -0700
SubjectVBScript to get most recent subject headings from specific (not inbox) folder
Message-ID<3b4371c1-0b5f-4c5a-a582-0187a18130f1@googlegroups.com>
Hi,

I'm confused about how to get emails from a specific folder.  Almost all of the examples on the web, are assuming that you're getting data from either inbox, or a subfolder of inbox.

The folder I'm trying to obtain the subject headings from, is called

   ThisSpecificFolder


, in this example.  There are several other folders, also on the same parent level as inbox.  But I'm interested only in this specific folder.



Dim objOutlook
Dim objNamespace
Dim colFolders
Dim objFldr
Dim objItms


Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set colFolders = objNamespace.Folders


'// This doesn't seem to be accomplishing it,
'//  but I'm not sure what to do next.

Set objFldr = objNamespace.Folders("ThisSpecificFolder")
Set objItms = objFldr.Items

[toc] | [next] | [standalone]


#12275

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2020-05-28 12:48 +0200
Message-ID<XnsABCB825D4C7D2eejj99@194.109.6.166>
In reply to#12274
Dan Campbell <dcwhatthe@gmail.com> wrote on 28 May 2020 in
microsoft.public.scripting.vbscript: 

> Hi,
> 
> I'm confused about how to get emails from a specific folder.  Almost all
> of the examples on the web, are assuming that you're getting data from
> either inbox, or a subfolder of inbox. 
> 
> The folder I'm trying to obtain the subject headings from, is called
> 
>    ThisSpecificFolder
> 
> 
> , in this example.  There are several other folders, also on the same
> parent level as inbox.  But I'm interested only in this specific folder. 
> 
> 
> 
> Dim objOutlook
> Dim objNamespace
> Dim colFolders
> Dim objFldr
> Dim objItms
> 
> 
> Set objOutlook = CreateObject("Outlook.Application")
> Set objNamespace = objOutlook.GetNamespace("MAPI")
> Set colFolders = objNamespace.Folders
> 
> 
> '// This doesn't seem to be accomplishing it,
> '//  but I'm not sure what to do next.
> 
> Set objFldr = objNamespace.Folders("ThisSpecificFolder")
> Set objItms = objFldr.Items

Methinks this is ment to be VBA, not VBS,
and this is a VBS-NG.

Look here:

<https://docs.microsoft.com/en-us/office/vba/outlook/concepts/getting-
started/automating-outlook-from-a-visual-basic-application>


-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#12276

From"Mayayana" <mayayana@invalid.nospam>
Date2020-05-28 08:13 -0400
Message-ID<rao9uq$qcm$1@dont-email.me>
In reply to#12275
"Evertjan." <exxjxw.hannivoort@inter.nl.net> wrote

| Methinks this is ment to be VBA, not VBS,
| and this is a VBS-NG.
|

   I just sent him here from the VB6 group. :)
The code looks like perfectly fine VBS to me.
But I don't have Outlook, so I can't test it.

  It probably *could* be used as VBA, but it's
written as Dispatch/late-bound code, so it should
be fine as VBS.

  There is an Outlook VBA newsgroup but I just took
a look and it's only getting about 1 post per year.
No one left but us old men. 

[toc] | [prev] | [next] | [standalone]


#12277

FromDan Campbell <dcwhatthe@gmail.com>
Date2020-05-28 06:08 -0700
Message-ID<f1d17e83-aec5-4958-82c1-f0013e3fa372@googlegroups.com>
In reply to#12275
On Thursday, May 28, 2020 at 6:49:00 AM UTC-4, Evertjan. wrote:
> Dan Campbell dc wrote on 28 May 2020 in
> microsoft.public.scripting.vbscript: 
> 
> > Hi,
> > 
> > I'm confused about how to get emails from a specific folder.  Almost all
> > of the examples on the web, are assuming that you're getting data from
> > either inbox, or a subfolder of inbox. 
> > 
> > The folder I'm trying to obtain the subject headings from, is called
> > 
> >    ThisSpecificFolder
> > 
> > 
> > , in this example.  There are several other folders, also on the same
> > parent level as inbox.  But I'm interested only in this specific folder. 
> > 
> > 
> > 
> > Dim objOutlook
> > Dim objNamespace
> > Dim colFolders
> > Dim objFldr
> > Dim objItms
> > 
> > 
> > Set objOutlook = CreateObject("Outlook.Application")
> > Set objNamespace = objOutlook.GetNamespace("MAPI")
> > Set colFolders = objNamespace.Folders
> > 
> > 
> > '// This doesn't seem to be accomplishing it,
> > '//  but I'm not sure what to do next.
> > 
> > Set objFldr = objNamespace.Folders("ThisSpecificFolder")
> > Set objItms = objFldr.Items
> 
> Methinks this is ment to be VBA, not VBS,
> and this is a VBS-NG.
> 
> Look here:
> 
> <https://docs.microsoft.com/en-us/office/vba/outlook/concepts/getting-
> started/automating-outlook-from-a-visual-basic-application>
> 
> 
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

Hi Everjian,

No, I'm using VBScript. The editor I'm using is VBSedit.  That's for VBScript, not VBA.

Anyway, thanks for the link, but I've been to that page.  It isn't helpful, because some of the objects it references are defined.

Anyway, I posted the question in an official VBScript forum.  We'll see what they say.

[toc] | [prev] | [next] | [standalone]


#12279

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2020-05-28 18:07 +0200
Message-ID<XnsABCBB86E2CA43eejj99@194.109.6.166>
In reply to#12277
Dan Campbell <dcwhatthe@gmail.com> wrote on 28 May 2020 in
microsoft.public.scripting.vbscript: 

>> Look here:
>> 
>> <https://docs.microsoft.com/en-us/office/vba/outlook/concepts/getting-
>> started/automating-outlook-from-a-visual-basic-application>
>> 

> 
> Hi Everjian,
> 
> No, I'm using VBScript. The editor I'm using is VBSedit.  That's for
> VBScript, not VBA. 
> 
> Anyway, thanks for the link, but I've been to that page.  It isn't
> helpful, because some of the objects it references are defined. 
> 
> Anyway, I posted the question in an official VBScript forum.  We'll see
> what they say. 

I never use Outlook, probably only for legacy reasons,
but I read somewhere that you need Outlook to be running.

==================

<https://stackoverflow.com/questions/9391849/opening-outlook-2010-through-
vbscript>

<https://support.foxtrotalliance.com/hc/en-us/articles/360021711752-How-To-
Automate-Outlook-With-VBScript>



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#12278

FromJJ <jj4public@vfemail.net>
Date2020-05-28 20:14 +0700
Message-ID<pqyja9mavb1g$.1b8bvx9zkiznh$.dlg@40tude.net>
In reply to#12274
On Wed, 27 May 2020 17:25:18 -0700 (PDT), Dan Campbell wrote:
> 
> Set objFldr = objNamespace.Folders("ThisSpecificFolder")

If that code can't be used to get the needed folder, you may want to do it
like this.

Set colFolders = objNamespace.Folders
For Each aFolder in colFolders
  If aFolder.Name = "ThisSpecificFolder" Then
    'process the folder here...
  End If
Next

If the folder isn't found, chances are that you're using the incorrect
folder name. In this case, you can simply call `MsgBox()` to display the
folder's `Name` property from within the loop, to find out the exact name of
the folders.

Do that for the folder items too, unless you only want to get a specific
item.

[toc] | [prev] | [next] | [standalone]


#12280

FromDan Campbell <dcwhatthe@gmail.com>
Date2020-05-28 14:02 -0700
Message-ID<9f24685e-a641-4766-9547-f8f650c5c521@googlegroups.com>
In reply to#12278
On Thursday, May 28, 2020 at 9:14:17 AM UTC-4, JJ wrote:
> On Wed, 27 May 2020 17:25:18 -0700 (PDT), Dan Campbell wrote:
> > 
> > Set objFldr = objNamespace.Folders("ThisSpecificFolder")
> 
> If that code can't be used to get the needed folder, you may want to do it
> like this.
> 
> Set colFolders = objNamespace.Folders
> For Each aFolder in colFolders
>   If aFolder.Name = "ThisSpecificFolder" Then
>     'process the folder here...
>   End If
> Next
> 
> If the folder isn't found, chances are that you're using the incorrect
> folder name. In this case, you can simply call `MsgBox()` to display the
> folder's `Name` property from within the loop, to find out the exact name of
> the folders.
> 
> Do that for the folder items too, unless you only want to get a specific
> item.

Thanks, JJ.  Here's the solution, prior to cleanup:


Dim objOutlook
Dim TargetFolder_s
Dim objNamespace
Dim colFolders

TargetFolder_s = "ThisSpecificFolder"
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set colFolders = objNamespace.Folders

RecurseFolders colFolders, TargetFolder_s



Set objOutlook = Nothing
Set objNamespace = Nothing
Set colFolders = Nothing


WScript.Quit



Sub RecurseFolders(objTheseFolders, TargetFolder_s)
Dim objItems
Dim objItem
Dim Subject_s
Dim var_s 
Dim FolderName_s
For Each ThisFolder In objTheseFolders
	FolderName_s = ThisFolder.Name
	If FolderName_s = "1_Responses_to_Me" Then
		WScript.Echo FolderName_s
		Set objItems = ThisFolder.Items
		
		For Each objItem In objItems
			Subject_s = objItem.Subject
			WScript.Echo Subject_s
		Next
	End If
	ReDim Preserve strPaths(i + 1)
	strPaths(i) = ThisFolder.FolderPath
	Set colFolders2 = ThisFolder.Folders
	i = i + 1
	RecurseFolders colFolders2, TargetFolder_s
Next
End Sub

[toc] | [prev] | [standalone]


Back to top | Article view | microsoft.public.scripting.vbscript


csiph-web