title image


Smiley Re: Daten an Word zum erstellen eines Briefes
Hallo Manuel,hier ein Beispiel (Übergabe an Word und anschl. Drucken und Speichern) anhand einer Access-Tabelle, Dim FName as String FName="Testdokument" 'Name des zu speichernden Dokumentes Dim RS As Recordset, DB As DATABASE Set DB = CurrentDb() Dim WordObj As Word.Application, WordDoc As Word.Document On Error Resume Next Set WordObj = GetObject(, "Word.Application ") If Err.Number 0 Then Set WordObj = CreateObject("Word.Application") On Error GoTo 0 With WordObj .Application.Visible = True Set WordDoc = .Documents.Add("C:\Vorlage.dot") Set RS = DB.OpenRecordset("SELECT * FROM [Tabellenname] " & _ "WHERE [Feldname] = 'xxx'", dbOpenDynaset) .ActiveDocument.Bookmarks("Anschrift").Select If RS.Fields("[Geschlecht]").Value = 0 Then .Selection.InsertAfter ("Herrn" & Chr(10)) Else .Selection.InsertAfter ("Frau" & Chr(10)) End If .Selection.InsertAfter (Nz(RS.Fields("[Vorname]").Value & _ " " & RS.Fields("[Nachname]").Value) & Chr(10)) .Selection.InsertAfter (Nz(RS.Fields("[Strasse]").Value & _ " " & RS.Fields("[Hausnummer]").Value) & _ Chr(10) & Chr(10)) .Selection.InsertAfter (Nz(RS.Fields("[PLZ]").Value & _ " " & RS.Fields("[Stadt]").Value)) .ActiveDocument.Bookmarks("IhrAnsprechpartner").Select .Selection.InsertAfter (NetUser) .ActiveDocument.Bookmarks("Durchwahl").Select .Selection.InsertAfter ("xxx") .ActiveDocument.Bookmarks("Faxnummer").Select .Selection.InsertAfter ("xxx") .ActiveDocument.Bookmarks("UnserZeichen").Select .Selection.InsertAfter ("xxx") .ActiveDocument.Bookmarks("Datum").Select .Selection.InsertAfter (Date) 'einfügen AutoText .ActiveDocument.Bookmarks("Text").Select .Selection.InsertAfter ("xxx") .Selection.Range.InsertAutoText .ActiveDocument.PrintOut Background:=False .ChangeFileOpenDirectory "\\'Speicherpfad einfügen'" .ActiveDocument.SaveAs FileName:="""" & FName & """", FileFormat:=wdFormatDocument .ActiveDocument.Close .Quit End With Set WordDoc = Nothing Set WordObj = Nothing RS.Close Set RS = NothingAnmerkung: Der Aufruf geschieht über Textfelder (incl. Textmarken), die in der Vorlage gespeichert worden sind)HTHGruß Thorsten

geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: