samesdavis Posted February 8, 2017 at 01:51 AM Report Share #602401 Posted February 8, 2017 at 01:51 AM Olá pessoal, Tenho um sistema que roda em vários micros e cada um deles com versões diferentes do office. O meu código não está dando certo, segue referenciei o outlook e usei o imports Imports Microsoft.Office.Interop Private Sub btnEnviar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnviar.Click Cursor.Current = Cursors.WaitCursor Try Dim tempApp As Microsoft.Office.Interop.Outlook.Application = New Microsoft.Office.Interop.Outlook.Application 'Dim tempApp = GetObject(, "Outlook.Application") Dim tempNS As Outlook.NameSpace Dim MailFolder As Outlook.MAPIFolder tempNS = tempApp.GetNamespace("MAPI") tempNS.Logon(, , True, True) Dim newMail As Outlook.MailItem = Nothing MailFolder = tempNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox) newMail = MailFolder.Items.Add(Outlook.OlItemType.olMailItem) With newMail .To = txtPara.Text .Subject = txtAssunto.Text .Body = txtMensagem.Text .Send() End With newMail = Nothing MailFolder = Nothing tempNS = Nothing tempApp = Nothing DialogResult = DialogResult.Yes Catch ex As Exception MsgBox(ex.ToString()) DialogResult = DialogResult.No Finally Cursor.Current = Cursors.Default End Try End Sub se eu usar essa linha Dim tempApp As Microsoft.Office.Interop.Outlook.Application = New Microsoft.Office.Interop.Outlook.Application ele só funciona no office2007 se eu usar essa linha, ele dá a mensagem de que não posso criar objeto activex Dim tempApp = GetObject(, "Outlook.Application") o que faço ? Link to comment Share on other sites More sharing options...
samesdavis Posted February 8, 2017 at 08:17 PM Author Report Share #602412 Posted February 8, 2017 at 08:17 PM Usei a linha Dim tempApp = CreateObject("Outlook.Application") Funcionou, porém só funciona se o Outlook estiver fechado, se estiver aberto, ele mostra uma mensagem de erro. no caso eu teria que fazer um loop nos processos abertos, fechar as instancias do outlook e abrir essa nova e no final fechar essa nova também. Link to comment Share on other sites More sharing options...
winseelan Posted January 31, 2020 at 02:08 PM Report Share #617243 Posted January 31, 2020 at 02:08 PM Hello Sam, Im facing the same issue, may i know how did you resolve this issue? could you please ellabrate little bit more? thank you jey Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now