Excel - Word - UserForm!

Folgender Code schreibt den Wert aus Tabellenblatt "Sheet1", Zelle "A1" in die "TextBox1" der "UserForm1" in der Templatedatei "C:\Temp\Doc1.dotm" - also entsprechend anpassen.

Excel - Word - UserForm...

Code:
Option Explicit
Sub Test()
Dim strPath As String
Dim objTB As Object
Dim oWord As Object
On Error GoTo Fin
Set oWord = CreateObject("Word.Application")
strPath = "C:\Temp\Doc1.dotm"

With oWord
.WordBasic.DisableAutoMacros 1
.Documents.Add Template:=strPath, NewTemplate:=False
.Visible = True
'.Activate 
Set objTB = .Documents.Application.Templates.Item(strPath). _
VBProject.VBComponents("UserForm1").Designer.Controls("TextBox1")
objTB.Text = ThisWorkbook.Worksheets("Sheet1").Range("A1")
End With
Fin:
Set objTB = Nothing
Set oWord = Nothing
End Sub

Beliebte Posts aus diesem Blog

Formeln - auch Array - per VBA eintragen...

Alle Dateien eines Ordners - Optional mit Unterordner

Excel -> Word in Textmarken (Bookmarks)...