AW: Ergänzung
25.03.2014 08:19:35
fcs
Hallo Albrecht,
eigentlich sollte die Wordversion keine Rolle spielen.
Allerdings muss man dann beim Speichern darauf achten, dass das Dokument im richtigen Formeat gespeichert wird. Dazu muss dann die Version von Word geprüft werden.
Kann dann etwawie folgt aussehen.
Gruß
Franz
Sub wordTest()
Dim DocNeu As Word.Document
Dim strDocName As String
Dim strPath As String
strPath = "C:\Users\Public\Test\Daten" 'ActiveSheet.Cells(1, 2)
strDocName = strPath & Application.PathSeparator & ActiveSheet.Cells(2, 2)
Set DocNeu = Word_Aktivieren("Brief", sichtbar:=True)
If Val(Left(DocNeu.Parent.version, 2)) > 11 Then
'Word 2007 und neuer
DocNeu.SaveAs2 Filename:=strDocName, _
FileFormat:=0, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False, CompatibilityMode:=0 'Fileformat: 0 = wdWordFormat, 12 = _
wdFormatXLMDocumet
Else
'frühere Version
DocNeu.SaveAs Filename:=strDocName 'Syntax nochmals prüfen !!1
End If
End Sub
Function Word_Aktivieren(Vorlage As String, sichtbar As Boolean) As Word.Document
Dim strTemplate As String
Dim version As Integer
Dim objWord As Object
'version = Workbooks("Kanzlei.xls").Sheets("Konstanten").Range("A54").Value
On Error Resume Next
Set objWord = GetObject("Word.Application")
If objWord Is Nothing Then
Set objWord = CreateObject("Word.Application")
End If
On Error GoTo 0
If Not objWord Is Nothing Then
objWord.Visible = True
strTemplate = Workbooks("Kanzlei.xls").Sheets("Konstanten").Range("aLW").Value _
& Workbooks("Kanzlei.xls").Sheets("Konstanten").Range("Vorlagen").Value _
& Workbooks("Kanzlei.xls").Sheets("Konstanten").Range(Vorlage).Value
Set Word_Aktivieren = objWord.Documents.Add(Template:=strTemplate)
End If
Set objWord = Nothing
End Function