I have a function that re-creates an email using the contents of another email (using the Outlook Redemption library). I have almost finished converting it to early binding (I am using Option Strict ON in vb.net), but visual studio 2010 underlines the .save and .move lines with the error "option strict on disallows late binding."
The code is:
'Use Redemption Library function to re-create email
Dim sItem As Redemption.SafeMailItem
Dim oItem As Object
sItem = New Redemption.SafeMailItem
oItem = myOlApp.Session.GetSharedDefaultFolder(myRecipient, Outlook.OlDefaultFolders.olFolderDrafts).Items.Add(Outlook.OlItemType.olMailItem)
With sItem
.Item = oItem
.Import(tempfilepath, 3) 'olMSG, olRFC822 and olTNEF formats are supported
.Save()
.Move(myolfolder)
End With
Having resolved the other late binding errors I cannot see why the two methods are flagging as a problem.
Help
Lewis
You get that error because SafeMailItem obly implements properties and methods blocked by Outlook.
Since Save and Move are not blocked, SafeMailItem does not implement them, but it is smart enough to pass them through when you are using late binding. Invoke those methods using the original Outlook item:
With sItem
.Item = oItem
.Import(tempfilepath, 3) 'olMSG, olRFC822 and olTNEF formats are supported
oItem.Save()
oItem.Move(myolfolder)
End With
Related
I have the below VBA code which i run to create a reply email.
Dim Reply As Outlook.MailItem
Dim Original As Outlook.MailItem
Set Original = Application.ActiveExplorer.Selection(1)
Set Reply = Original.ReplyAll
Reply.Subject = "RE: " & Original.Subject
Reply.Display
I have the following variable and have been unsuccessfully trying to paste it into "Reply" above.
Dim tTable As Word.Table
Word is used as an email editor in Outlook. You can use the WordEditor property of the Inspector class to get an instance of the Document class which represents the Body of the email. Thus, you will be able to use objects, their properties and methods available in the Word object model when working with item bodies.
You can read about all possible ways in the Chapter 17: Working with Item Bodies article in MSDN.
I am trying to update an VBA module to use the System.Windows.Forms.FolderBrowserDialog class. I declared my object as follows:
Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog
Running this gave me the error User-defined type not defined. I figured the compiler didn't know about that class so I tried going to Tools > References and adding Systems_Windows_Forms, but I'm still getting the same error. Does anyone know what I'm missing here? Do I need a reference to the library in my code as well?
System.Windows.Forms.FolderBrowserDialog looks like something from .Net to me, not VBA.
You can use Application.FileDialog in Access VBA. This sample uses late binding and allows the user to select a folder from a browse dialog.
Const msoFileDialogFolderPicker As Long = 4
Dim objFileDialog As Object ' FileDialog
Set objFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
With objFileDialog
.AllowMultiSelect = False
If .Show Then
Debug.Print .SelectedItems(1)
End If
End With
If you prefer to use early binding, set a reference to the Microsoft Office [version] Object Library. You could then declare the object like this ...
Dim objFileDialog As FileDialog
And you wouldn't need to define the constant, so discard this line if using early binding ...
Const msoFileDialogFolderPicker As Long = 4
I need to mimic the adress book control in an Outlook VSTO project. It would be much simpler to use the real control, isn't it?
So, do you know a way to expose the address book control, and get what's selected within, of course?
Edit: Never mind, re-creating a basic version of the control will be way easyer.
Solution: third party Redemption library offer this feature.
RedemptionLoader.RDOSession.AddressBook.ShowAddressBook(...)
You don't need to use a third party addin. you can do it with this:
http://msdn.microsoft.com/en-us/library/office/ff868361.aspx
this code below is in VBA but you can easily convert it to C#:
Sub SelectRecipients()
Dim oMsg As MailItem
Set oMsg = Application.CreateItem(olMailItem)
Dim oDialog As SelectNamesDialog
Set oDialog = Application.Session.GetSelectNamesDialog
With oDialog
.InitialAddressList = _
Application.Session.GetGlobalAddressList
.Recipients = oMsg.Recipients
If .Display Then
'Recipients Resolved
oMsg.Subject = "Hello"
oMsg.Send
End If
End With
End Sub
How to get all the functions you have in a code file in Visual Studio using VS macros?
I`m using Visual Studio 2008.
Also I need to get whether function is private protected or public. For now I know I can just parse the code and check it on my own, but I want to make it in a proper way and think vs macros environment should allow know all info about functions.
See HOWTO: Navigate the code elements of a file from a Visual Studio .NET macro or add-in
An maybe HOWTO: Navigate the files of a solution from a Visual Studio .NET macro or add-in would be interesting for you.
Getting function accessibility is easy. Following the first article, you have CodeElement object. If it is of type CodeFunction, you can cast it to CodeFunction (or also to CodeFunction2) type. The CodeFunction contains many properties including Access which is what you need. I have modified ShowCodeElement from this article so it only shows functions and also displays their accessibility:
Private Sub ShowCodeElement(ByVal objCodeElement As CodeElement)
Dim objCodeNamespace As EnvDTE.CodeNamespace
Dim objCodeType As EnvDTE.CodeType
Dim objCodeFunction As EnvDTE.CodeFunction
If TypeOf objCodeElement Is EnvDTE.CodeNamespace Then
objCodeNamespace = CType(objCodeElement, EnvDTE.CodeNamespace)
ShowCodeElements(objCodeNamespace.Members)
ElseIf TypeOf objCodeElement Is EnvDTE.CodeType Then
objCodeType = CType(objCodeElement, EnvDTE.CodeType)
ShowCodeElements(objCodeType.Members)
ElseIf TypeOf objCodeElement Is EnvDTE.CodeFunction Then
Try
Dim msg As String = objCodeElement.FullName & vbCrLf
Dim cd As EnvDTE.CodeFunction = DirectCast(objCodeElement, CodeFunction)
Select Case cd.Access
Case vsCMAccess.vsCMAccessDefault
msg &= "Not explicitly specified. It is Public in VB and private in C#."
Case Else
msg &= cd.Access.ToString
End Select
MsgBox(msg)
Catch ex As System.Exception
' Ignore
End Try
End If
End Sub
Change it and execute ShowFileCodeModel macro then.
I would like to read MSG file stored on the filesystem and do the following:
Read the body text of the msg file.
Open and save the attachments in the MSG file.
Is it possible using the msoutl.olb#Microsoft Outlook 10.0 Object Library?
I would like to avoid using Outlook Redemption v. 4.7 based
on question MSG Read Stackoverflow question
Thank you.
I believe you can. Try adding a reference to the Outlook 10 object library and then try this code:
Dim OL As Outlook.Application
Dim Msg As Outlook.MailItem
Set OL = New Outlook.Application
Set Msg = OL.CreateItemFromTemplate("c:\msg.msg")
' now use msg to get at the email parts
MsgBox Msg.Subject
Set OL = Nothing
Set Msg = Nothing
I can't vouch for any of the methods or properties of your Outlook.MailItem object (msg) but give it a shot and see.