Hi,
I've got this vb6 code that compiles into a dll. the code creates an outlook toolbar.
I'd like to get the current outlook folder name (so to use it as a paramater)
do you know the syntax for that?
thanks,
Printable View
Hi,
I've got this vb6 code that compiles into a dll. the code creates an outlook toolbar.
I'd like to get the current outlook folder name (so to use it as a paramater)
do you know the syntax for that?
thanks,
Does this help?
you might have to tweak it a little...
http://www.freevbcode.com/ShowCode.Asp?ID=1064
That just gets all the folders, not the selected one.
What version of Outlook? In 2003 there is a .CurrentFolder property.
vb Code:
'Assumes oApp (Outlook.Application) object is already created Dim oExp As Outlook.Explorer Dim oBox As Outlook.MAPIFolder Set oExp = oApp.ActiveExplorer Set oBox = oExp.CurrentFolder MsgBox oBox.Name
oApp - variable not defined
Read the code comment
I've tried to add dim oApp as Outlook.Application, but my application stopped working after that.
here's the context
Public Function SaveMailAsMSG(ByRef Item As Outlook.MailItem, _
ByVal ItemNo As Long, _
ByVal FilingNo As Long, ByVal FilingArea As Long) As Boolean
Dim fname As String
Dim reqdir As String
Dim filingnotes As String
Dim lBackslashPos, sPartialPath
' Dim oExp As Outlook.Explorer
' Dim molTrustedApp As Outlook.Application
' Set oExp = molTrustedApp.ActiveExplorer
On Error GoTo error_filing
'create the item file name.
fname = Right(ReplaceIllegalChars(Item.Subject), 50)
' MsgBox oExp.CurrentFolder
' fname = fname & "_" & Right(ReplaceIllegalChars(oExp.CurrentFolder), 50)
Look at the code. See oApp is defined as an Outlook.Application? Now you have molTrustedApp which appears to be an Outlook.Application too. Just switch them out and use only molTrustedApp.
I did the molTrustedApp definition (instead of oaPP, and have not used oApp anywhere)
Is molTrustedApp already created and Outlook displayed?
I'll try to explain the bigger picture. I got a vb6 code that is compiled as a dll and is used in outlook2003 to create a toolbar. the toolbar has buttons to save the current message in outlook as an msg file to a specific folder.
I'd like the name of the msg file to contain the outlook folder that it is stored in.
please let me know if this explains it better, or if you would like to know further details,
thanks,
Well thats not what you had asked. Only asked for getting a currently selected folder.
Ok, now with that scenerio
Just attach an object variable to the current selected object. You may want to verify that its a MailItem object too.
Dim oMsg As Outlook.MailItem
Set oMsg = oExp.Selection
I only tried to explain the big picture- I've got all the code working (it stores the message) except for to make the folder name a part of the msg filename.
I don't know why what you sent is not working...
thanks,
and also, maybe you can answer my other thread for the same code: how to open up an explorer window from this dlll (as a button on the toolbar).
thanks,
Well I dont have all your project so I cant say why its not working but the code does do what you asked. Just need to implement it into your code correctly.
here it is:
Public Function SaveMailAsMSG(ByRef Item As Outlook.MailItem, _
ByVal ItemNo As Long, _
ByVal FilingNo As Long, ByVal FilingArea As Long) As Boolean
Dim fname As String
Dim reqdir As String
Dim filingnotes As String
Dim lBackslashPos, sPartialPath
' Dim oExp As Outlook.Explorer
' Dim molTrustedApp As Outlook.Application
' Set oExp = molTrustedApp.ActiveExplorer
'create the item file name.
fname = Right(ReplaceIllegalChars(Item.Subject), 50)
' MsgBox oExp.CurrentFolder
' fname = fname & "_" & Right(ReplaceIllegalChars(oExp.CurrentFolder), 50)
fname = "Mail" & "_" & _
Day(Date) & "_" & Month(Date) & "_" & Year(Date) & "_" & _
fname & _
"-" & Hour(Now) & Minute(Now) & Second(Now)
reqdir = FILING_DIR & "\" & FilingArea & "\" & ItemNo
reqdir = reqdir & "\" & FilingNo
filingnotes = reqdir & "\" & fname
filingnotes = filingnotes & ".msg"
'save filing item
Item.SaveAs filingnotes, olMSG
end function
I still dont see where you have your application object variable?
do you mean the definitions in the start of the module ?
Option Explicit
DefStr S: DefBool B: DefLng L: DefCur C: DefDate D
DefByte Y: DefInt I: DefSng N: DefDbl U
Private cn As ADODB.Connection
Private cmFilings As ADODB.Command
Private colStationIds As Collection
Private colFilingAreaIds As Collection
Private colFilingIds As Collection
Private bmIsConnected
Where is it being created and what is the definition of "molTrustedApp"?
please look at the function (2 messages ago)
Dim molTrustedApp As Outlook.Application
thanks,
But it is commented out and not used. Is it originally somewhere else? You need to have the application object created somewhere?
yes, as I said when I didn't commented out the whole part of the folder name, this function didn't work at all (I got no error messages- even on error event didn't occur (it just didn't save the item as msg). when I tried to display its value using msgbox it didn't show any message box at all. that is why you see all of the related code commented out.
I'm sorry but you are just not getting it. In order for your app or addin or whatever it is to automate or integrate with outlook you need an application object. You cant export your msgs just with the code you posted.
I just noticed your reply...
you are right- I don't get it!
here's the function again, with the commented parts not commented. please try to explain / add the missing code to make it work.
thanks,
Public Function SaveMailAsMSG(ByRef Item As Outlook.MailItem, _
ByVal ItemNo As Long, _
ByVal FilingNo As Long, ByVal FilingArea As Long) As Boolean
Dim fname As String
Dim reqdir As String
Dim filingnotes As String
Dim lBackslashPos, sPartialPath
Dim oExp As Outlook.Explorer
Dim molTrustedApp As Outlook.Application
Set oExp = molTrustedApp.ActiveExplorer
'create the item file name.
fname = Right(ReplaceIllegalChars(Item.Subject), 50)
fname = fname & "_" & Right(ReplaceIllegalChars(oExp.CurrentFolder), 50)
fname = "Mail" & "_" & _
Day(Date) & "_" & Month(Date) & "_" & Year(Date) & "_" & _
fname & _
"-" & Hour(Now) & Minute(Now) & Second(Now)
reqdir = FILING_DIR & "\" & FilingArea & "\" & ItemNo
reqdir = reqdir & "\" & FilingNo
filingnotes = reqdir & "\" & fname
filingnotes = filingnotes & ".msg"
'save filing item
Item.SaveAs filingnotes, olMSG
end function
If this is your addin then there has to be some other outlook code then the three lines of code I posted. Do you have some other outlook code?
Dim oExp As Outlook.Explorer
Dim molTrustedApp As Outlook.Application
Set oExp = molTrustedApp.ActiveExplorer
This alone will not do it.
the code has several modules. the module of this function doesn't have any other outlook defintions. but another module that calls this function has several outlook global definitions in the start of the module :
Private molTrustedApp As Outlook.Application
Private WithEvents mcolInspectors As Outlook.Inspectors
Private colInspectorToolbars As Collection
Private WithEvents mcolExplorers As Outlook.Explorers
Private colExplorerToolbars As Collection
Private lInspectorULimit, lExplorerULimit
Private WithEvents colSentItems As Outlook.Items
and on another module:
------------------------
Private Const EXPLORER_TAG_PREFIX As String = "EXPLORER"
Private WithEvents mxplOpened As Outlook.Explorer
Private mclsParentApp As CAccessOL
Private mlUnderlying As Outlook.MailItem
Private lmUniqueIndex
Private barAccessOLToolbar As Office.CommandBar
the other module that defines the toolbar:
------------------------------------------
Private Const INSPECTOR_TAG_PREFIX As String = "INSPECTOR"
Private WithEvents mispExisting As Outlook.Inspector
Private mclsParentApp As CAccessOL
Private lmUniqueIndex
Private WithEvents mlUnderlying As Outlook.MailItem
Private barAccessOLToolbar As Office.CommandBar
Private cboFilings As Office.CommandBarComboBox
Private cboStations As Office.CommandBarComboBox
Private WithEvents cboFilingAreas As Office.CommandBarComboBox
Private WithEvents btnSubmit As Office.CommandBarButton
Private WithEvents btnSendNSubmit As Office.CommandBarButton
Private btnStatus As Office.CommandBarButton
Private WithEvents cboFilings As Office.CommandBarComboBox
Private cboStations As Office.CommandBarComboBox
Private WithEvents cboFilingAreas As Office.CommandBarComboBox
Private WithEvents btnSubmit As Office.CommandBarButton
Private WithEvents btnSendNSubmit As Office.CommandBarButton
Private btnStatus As Office.CommandBarButton
can I ask you to respond to my very new threads about the same dll code on "office development" ?
thanks,
Ok, now we are getting somewhere. The one thing I see its that all the ourlook object variables are declared Private. Are they only used in the module and perhaps passed in functions?
What Im trying to find is where and what your Outlook.Application object variable is called and if its not public then how are we able to access it.
See the ...
Private WithEvents mcolExplorers As Outlook.Explorers
declaration in a module is what we can use to set the oExp object variable but how can you reference it if its Private to that one particular module?
the function is called with the paramater of the current email item which is defined as mlUnderlying (Set mlUnderlying = ispExisting.CurrentItem , or Set mlUnderlying = mxplOpened.Selection.Item(1))
did you mean to ask about that?