chefe332211
Goto Top

Outlook und VB.net

Hallo,
ich möchte mit VB.net Outlook mit einer bestimmten oft.Datei zu öffnen. Scheitere aber im Moment noch am öffnen von Outlook.
Hat jemand einen Beispiel-Source um das zu realisieren?

Bislang sieht der Code so aus
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class Form1
    Inherits System.Windows.Forms.Form
    'Form overrides dispose to clean up the component list.  
    <System.Diagnostics.DebuggerNonUserCode()>
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub
    'Required by the Windows Form Designer  
    Private components As System.ComponentModel.IContainer
    'NOTE: The following procedure is required by the Windows Form Designer  
    'It can be modified using the Windows Form Designer.    
    'Do not modify it using the code editor.  
    <System.Diagnostics.DebuggerStepThrough()>
    Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '  
        'Button1  
        '  
        Me.Button1.Location = New System.Drawing.Point(251, 76)
        Me.Button1.Name = "Button1"  
        Me.Button1.Size = New System.Drawing.Size(224, 106)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Button1"  
        Me.Button1.UseVisualStyleBackColor = True
        '  
        'Form1  
        '  
        Me.AutoScaleDimensions = New System.Drawing.SizeF(7.0!, 15.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(800, 450)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"  
        Me.Text = "Form1"  
        Me.ResumeLayout(False)
    End Sub
    Friend WithEvents Button1 As Button
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            'Schaut ob Outlook läuft Notfalls wird er Gestartet.  
            Dim p() As Process
            p = Process.GetProcessesByName("Outlook.exe")  
            If p.Count > 0 Then
            Else
                Process.Start("Outlook.exe")  
            End If
            'Hier wird die Email erstellt und Versendet.  
            Dim outlookapi As Object
            Dim outlookItem As Object
            outlookapi = CreateObject("Outlook.application")  
            outlookItem = outlookapi.outlookapi.createitem(0)
            With outlookItem
                .Subject = "BETREFF ALS STRING"  
                .To = "EMPFÄNGER ALS STRING"  
                .HTMLbody = "INHALT ALS STRING"  
                .Send 'Versendet die Email selbständig, ohne Outlook' Email Fenster anzuzeigen.  
                ' .Attachments.Add(FILEPATH) - Falls du noch ein Anhang haben möchtest, schreibe das nach HTMLbody hinzu.  
            End With
            outlookapi = Nothing
            outlookItem = Nothing
            Exit Sub
            outlookapi = Nothing
            outlookItem = Nothing
        Catch ex As System.Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class

Aber es bricht ab mit der Meldung "Public Member 'Outlookapi' on type 'Application' not found

Vielen Dank für eure Bemühungen
fehler

Content-Key: 2041316801

Url: https://administrator.de/contentid/2041316801

Printed on: April 26, 2024 at 21:04 o'clock

Mitglied: 1915348599
1915348599 Mar 02, 2022 updated at 11:31:40 (UTC)
Goto Top
ich möchte mit VB.net Outlook mit einer bestimmten oft.Datei zu öffnen.
Application.CreateItemFromTemplate-Methode (Outlook)
outlookapi.outlookapi.createitem(0)
Doppelt gemoppelt jeht ned ... Kaffee einschenk.
Member: Chefe332211
Chefe332211 Mar 02, 2022 at 12:26:15 (UTC)
Goto Top
Hallo Pretty,

danke für den Hinweis zu zur doppelten outlookapi, hat leider das Problem nicht gelöst.
Aber danke
Mitglied: 1915348599
1915348599 Mar 02, 2022 updated at 15:23:20 (UTC)
Goto Top
Ist ja ehrlich gesagt auch Schmuh hier mit dem COM-Object zu hantieren, dafür gibt es für .NET die Primary Interop Assemblies für Outlook
https://docs.microsoft.com/de-de/dotnet/api/microsoft.office.interop.out ...
Referenz dazu hinzufügen und ein Application-Objekt erzeugen, feddisch ist die Soße.

screenshot

Imports Microsoft.Office.Interop

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim olApp As Outlook.Application = New Outlook.Application()
        With olApp
            With .CreateItem(Outlook.OlItemType.olMailItem)
                .Subject = "Test"  
                .display()
            End With
        End With
    End Sub
End Class

Willst du stattdessen ein MailObjekt von einer *.OFT-Vorlage erzeugen, was du ja laut deiner Aussage im Titel möchtest, machst du das mit der oben schon verlinkten Methode "CreateItemFromTemplate"
Imports Microsoft.Office.Interop

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim olApp As Outlook.Application = New Outlook.Application()
        With olApp
            With .CreateItemFromTemplate("D:\Ordner\vorlage.oft")  
                .display()
            End With
        End With
    End Sub
End Class