Sub TransferToWord()
Dim oApp As Word.Application
Set oApp = GetApplication("Word.Application")
If oApp Is Nothing Then
MsgBox "..."
Exit Sub
End If
Dim oDoc As Word.Document
Set oDoc = oApp.Documents.Add
' ab hier kannst Du direkt ins Document schreiben
' Der Weg über die Zwischenablage ist nicht notwendig!
' Zum Abschluss wieder alles freigeben
Set oDoc = Nothing
Set oApp = Nothing
End Sub
Function GetApplication(ByVal AppClass As String) As Object
Const vbErr_AppNotRun = 429
On Error Resume Next
Set GetApplication = GetObject(Class:=AppClass)
If Err.Number = vbErr_AppNotRun _
Then Set GetApplication = CreateObject(AppClass)
On Error GoTo 0
End Function
Sub sWordAdr()
' Inhalte der Zellen A1 und A2 der 1. EXCEL- Tabelle in ein neues
' Word- Dokument übertragen und unter E:\Word.doc speichern
Dim i, iMax
Const cDateiName = "C:\test\Word.doc"
Dim AppWord As Object
iMax = Cells(Rows.Count, 1).End(xlUp).Offset(0, 1).Row
Set AppWord = CreateObject("Word.Application")
With AppWord ' *** ab jetzt "Word- VBA"
.Visible = True
.Activate
.Documents.Add ' leere Word- Blatt
End With
For i = 1 To iMax
Dim VorName As String: VorName = Worksheets(1).Cells(i, 1).Value
Dim NachName As String: NachName = Worksheets(1).Cells(i, 2).Value
Dim stnr As String: stnr = Worksheets(1).Cells(i, 3).Value
With AppWord
.Selection.TypeText VorName & ", " & NachName & " Stempelindex: " & stnr
.Selection.TypeParagraph ' Zeilenschaltung
.Selection.TypeParagraph
'.Selection.TypeText NachName
End With
Next
With AppWord
'.ActiveDocument.SaveAs FileName:=cDateiName
'.Quit ' Word beenden
End With ' *** ab jetzt wieder EXCEL- VBA
Set AppWord = Nothing
End Sub
Sub gueltigkeit()
If IsNumeric(Cells(1, 1).Value) = True Then
MsgBox "Zahlen " & IsNumeric(Cells(1, 1).Value)
Else
MsgBox "Buchstaben"
End If
End Sub
Sub Transfer_zu_Word_1()
Dim ws As Worksheet, rg1 As Range, rg2 As Range, _
s As String, i As Integer
Set ws = ThisWorkbook.Worksheets("Tabelle1")
Set rg1 = ws.Range("C6:C10")
Dim objWordApp
Dim objWordDoc
Dim objTB
Dim intI As Integer
'Mit geöffneter Word-Applikation connecten
Set objWordApp = GetObject(, "Word.Application")
objWordApp.Visible = True
i = 0
For Each rg2 In rg1
i = i + 1
s = CStr(rg2.Value)
objWordApp.Run "datenInUserform1", i, s
Next rg2
Set rg2 = Nothing
Set rg1 = Nothing
Set ws = Nothing
Set objWordApp = Nothing
End Sub
Sub TransferToWord()
Dim oApp As Word.Application
Set oApp = GetApplication("Word.Application")
If oApp Is Nothing Then
MsgBox "..."
Exit Sub
End If
Dim oDoc As Word.Document
Set oDoc = oApp.Documents.Add
' ab hier kannst Du direkt ins Document schreiben
' Der Weg über die Zwischenablage ist nicht notwendig!
' Zum Abschluss wieder alles freigeben
Set oDoc = Nothing
Set oApp = Nothing
End Sub
Function GetApplication(ByVal AppClass As String) As Object
Const vbErr_AppNotRun = 429
On Error Resume Next
Set GetApplication = GetObject(Class:=AppClass)
If Err.Number = vbErr_AppNotRun _
Then Set GetApplication = CreateObject(AppClass)
On Error GoTo 0
End Function
Sub sWordAdr()
' Inhalte der Zellen A1 und A2 der 1. EXCEL- Tabelle in ein neues
' Word- Dokument übertragen und unter E:\Word.doc speichern
Dim i, iMax
Const cDateiName = "C:\test\Word.doc"
Dim AppWord As Object
iMax = Cells(Rows.Count, 1).End(xlUp).Offset(0, 1).Row
Set AppWord = CreateObject("Word.Application")
With AppWord ' *** ab jetzt "Word- VBA"
.Visible = True
.Activate
.Documents.Add ' leere Word- Blatt
End With
For i = 1 To iMax
Dim VorName As String: VorName = Worksheets(1).Cells(i, 1).Value
Dim NachName As String: NachName = Worksheets(1).Cells(i, 2).Value
Dim stnr As String: stnr = Worksheets(1).Cells(i, 3).Value
With AppWord
.Selection.TypeText VorName & ", " & NachName & " Stempelindex: " & stnr
.Selection.TypeParagraph ' Zeilenschaltung
.Selection.TypeParagraph
'.Selection.TypeText NachName
End With
Next
With AppWord
'.ActiveDocument.SaveAs FileName:=cDateiName
'.Quit ' Word beenden
End With ' *** ab jetzt wieder EXCEL- VBA
Set AppWord = Nothing
End Sub
Sub gueltigkeit()
If IsNumeric(Cells(1, 1).Value) = True Then
MsgBox "Zahlen " & IsNumeric(Cells(1, 1).Value)
Else
MsgBox "Buchstaben"
End If
End Sub
Sub Transfer_zu_Word_1()
Dim ws As Worksheet, rg1 As Range, rg2 As Range, _
s As String, i As Integer
Set ws = ThisWorkbook.Worksheets("Tabelle1")
Set rg1 = ws.Range("C6:C10")
Dim objWordApp
Dim objWordDoc
Dim objTB
Dim intI As Integer
'Mit geöffneter Word-Applikation connecten
Set objWordApp = GetObject(, "Word.Application")
objWordApp.Visible = True
i = 0
For Each rg2 In rg1
i = i + 1
s = CStr(rg2.Value)
objWordApp.Run "datenInUserform1", i, s
Next rg2
Set rg2 = Nothing
Set rg1 = Nothing
Set ws = Nothing
Set objWordApp = Nothing
End Sub