Hi Leute,
ich soll irgendwie ein Outlook Kontakt durch anklicken in einem Word Dokument öffnen. Da ich leider absolut keine Ahnung von dem Zeugs hab und es eigentlich auch nicht mein Bereich ist, häng ich gerade ein bißchen durch.
Das ganze soll als Makro in Outlook laufen.
Ich hab in VS2005 ein bißchen experimentiert, das öffnen klappt, nur der Zugriff auf die Outlook Kontakte klappt nicht.
Allerdings klappt das leider nicht unter Outlook.
Kann mir jemand bitte weiterhelfen?
Vielen Dank im voraus!
___________________________________________
Imports Word = Microsoft.Office.Interop.Word
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim oWord As Word.Application 'Variablendeklaration als Word appl.
Dim oDoc As Word.Document 'Variablendeklaration als Word appl.
Dim oPara1 As Word.Paragraph, oPara2 As Word.Paragraph 'Erzeugt einen Absatz
Dim oPara3 As Word.Paragraph
'****************************************************************
'Je Nach Wunsch muss eins auskommentiert werden.
'Im Moment wird ein neues Word Dokument und eine Vorlage geöffnet
'erwünscht ist meines Wissens nach nur ein neues Dokument
'****************************************************************
'Start Word and open the document template. New Word
oWord = CreateObject("Word.Application") 'erzeugt ein neues Word Object
oWord.Visible = True 'Das Word Dokument wird beim öffnen angezeigt
oDoc = oWord.Documents.Add 'kürzt den Befehl oWord.Documents.Add in oDoc ab
'Insert a paragraph at the beginning of the document.
oPara1 = oDoc.Content.Paragraphs.Add 'gibt die Pos. des Absatzes ein
oPara1.Range.Text = "Text 1" 'Befehl für Texterzeugung
oPara1.Range.Font.Bold = True 'Befehl für Fettschrift
oPara1.Format.SpaceAfter = 24 '24 leerzeichen nach Absatz.
oPara1.Range.InsertParagraphAfter()
''Insert a paragraph at the end of the document.
''** \endofdoc is a predefined bookmark.
oPara2 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range) 'Pos. ist am Dokumentenende
oPara2.Range.Text = "Text 2"
oPara2.Format.SpaceAfter = 6
oPara2.Range.InsertParagraphAfter()
''Uses a Template to open Word. Old Word
oWord.Documents.Add("C:\Vorlagen\dok.dotx") 'gibt den Ort der zu öffnenden Dateivorlage an
oDoc.Bookmarks.Item("test").Range.Text = "Nur zu testzwecke" 'fügt der Textmarke namens "test" einen Text hinzu
'Insert another paragraph.
oPara3 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
oPara3.Range.Text = "This is a sentence of normal text. Now here is a table:"
oPara3.Range.Font.Bold = False
oPara3.Format.SpaceAfter = 24
oPara3.Range.InsertParagraphAfter()
Me.Close()
End Sub
End Class
____________________________________________________________
Das hier ist unter Outlook geschrieben, da klappt aber nichts... =(
Die Kommentare kann man getrost Ignorieren. Sie dienen bei mir als Hilfe damit ich weiß um was es geht...
____________________________________________________________
Option Explicit
Dim objoutlook As Outlook.Application 'Outlook als Objekt festlegen
Dim objnamespace As NameSpace 'aktuellen Arbeitsbereich von Outlook mit dem Namespace festlegen
Dim objmapifolder As MAPIFolder 'Der Mapi-Folder legt den Kontaktordner fest
Dim objitems As Items 'Items sind die einzelnen Kontakeinträge
Dim aktuser As String 'Speicherung des Usernames
Private Sub CommandButton1_Click()
Kontakte_Lesen 'Kontakte auslesen und anzeigen
Kontakte_in_Word 'Kontakte in Word kopieren
End Sub
Function Kontakte_Lesen()
Set objoutlook = New Outlook.Application 'Outlook initialisieren
Set objnamespace = objoutlook.GetNamespace("MAPI") 'Namespace initialisieren
aktuser = objnamespace.CurrentUser 'Aktuellen User im Outlook ermitteln
Set objmapifolder = objnamespace.GetDefaultFolder(olFolderContacts) 'Kontakt Ordner setzen
Set objitems = objmapifolder.Items 'Items initialieren
Kontakte_Lesen -objitems.LastName & ", " & objitems.FirstName
End Function
Private Sub Kontakte_in_Word()
Dim oword As Word.Application
Dim odoc As Word.Document
Dim opara1 As Word.Paragraph
öword = CreateObject("Word.Application") 'neues Word Dokument erstellen
oword = Visible = True 'beim öffnen angezeigt lassen
odoc = oword.documents.Add
End Sub