Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
876to880
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
876to880
876to880
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Word speichern, Fehler im Makro?

Word speichern, Fehler im Makro?
12.06.2007 08:13:00
marcl
Moin zusammen,
ich habe ein Mkro gefunden, mit dem man Wordokumente aus Excel hereua peichern kann. Leider funktioniert das nicht so, wie ich mir vorgestellt habe. Was mache ich falsch?

Sub amr()
pfadname = Range("A101")
Dim wd As Object
Set wd = CreateObject("word.Application")
Dim wrdFileName As String
monat = Range("A200")
Jahr = Format(Date, "YYYY")
Application.DisplayAlerts = False
wrdFileName = "http://.../"
& Jahr & monat & "/a_" & Range("A6") &  _
".doc"
CreateObject("word.application").Documents.Open(wrdFileName).Application.Visible = True '
Set wdanw = CreateObject("Word.Application")
wdanw.Application.DisplayAlerts = False
wdanw.ActiveDocument.Save
wdAnd.Application.DisplayAlerts = True
End Sub


Gruß
marcl

2
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Word speichern, Fehler im Makro?
12.06.2007 21:43:00
Dan
Hi Marc, der Code den Du versucht ze benutzen kann nicht funktionieren...es ist Unsinn.
Hier ein simple Example. Ich habe englische Komenare hinzugefueght, also das einzige was Du machen musst eher Du den Code ausfuerhst ist : einen gueltigen Pfad in die Zelle A1 schreiben. Gruss Dan, cz.
Option Explicit
' Range("A1") must contain a valid path...this is a path, where the new doc. will be saved

Sub CreateNewWordDocument()
On Error GoTo Err_CreateNewWordDocument
' if you set reference to the word object library, you can uncomment the types in  _
declarations
Dim wordApplication ' As Word.Application
Dim wordDocument ' As Word.Document
Dim saveToPath As String
' and here you can use the early binding as well ... New Word.Application instead of VBA. _
CreateObject("word.Application")
Set wordApplication = VBA.CreateObject("word.Application") ' New Word.Application
Set wordDocument = wordApplication.Documents.Add
saveToPath = Range("A1") & "\" & VBA.Format(VBA.Date, "mmmm") & VBA.Format(VBA.Date, "yyyy") _
wordDocument.SaveAs saveToPath
VBA.MsgBox "New word document was saved to path : " & wordDocument.Path
wordDocument.Close
wordApplication.Quit
Set wordDocument = Nothing
Set wordApplication = Nothing
Exit Sub
Err_CreateNewWordDocument:
VBA.MsgBox Err.Description, vbCritical, "Error in CreateNewWordDocument"
If (Not wordApplication Is Nothing) Then
wordApplication.Quit
Set wordApplication = Nothing
End If
End Sub


Anzeige
Danke
13.06.2007 09:41:00
makl
Jo, jetzt, wo es kein Unsinn mehr ist, funktioniert es super.
Vielen Dank.
Gruß
marcl

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige