AW: VBA Textmarken in Word aus exel füllen
07.07.2023 23:10:08
Ulf
Hi
Reginas Code funzt, die Sprach/Ländereeinstellungen bei Mac können aber Punkt als Trennzeichen haben. Kann man mit Intellisense aber sehen
Würde aber Documents.Add nutzen, dann ist nur ein ungespeichertes Dokument offen
Sub test()
Dim AppWD As Object
Dim doc As Object
Dim strDoc As String
'Early Binding:
'Set AppWD = New Word.Application
'Dim doc As Word.Document
'Für Speichern
Const wdFormatDocumentDefault = 16
Set AppWD = CreateObject("Word.Application")
'strDoc = ActiveWorkbook.Path & "\Test Textmarke.docx"
strDoc = "/Volumes/Macintosh HD - Daten/PraxisNeu/GeschäftsbriefTest1.docx"
AppWD.Visible = True
Set doc = AppWD.Documents.Add(strDoc) '"/Volumes/Macintosh HD - Daten/PraxisNeu/GeschäftsbriefTest1.docx"
With doc
.Bookmarks("Name").Range.Text = Tabelle1.Cells(2, 1).Value
.Bookmarks("Vorname").Range.Text = Tabelle1.Cells(2, 2).Value
.Bookmarks("Strasse").Range.Text = Tabelle1.Cells(2, 3).Value
.Bookmarks("PLZ").Range.Text = Tabelle1.Cells(2, 4).Value
.Bookmarks("Ort").Range.Text = Tabelle1.Cells(2, 5).Value
.Bookmarks("Anrede").Range.Text = Tabelle1.Cells(2, 6).Value
.Saved = True
'.SaveAs2 ActiveWorkbook.Path & "\" & Format(Date, "yyyy_MM_dd") & "_" & Format(Time, "hh_nn_ss") & ".docx", wdFormatDocumentDefault
'Zum Testen
Stop
.Close
End With
AppWD.Quit
Set AppWD = Nothing
End Sub
hth
Ulf