Hallo zusammen,
ich habe einen Code zur Erstellung eines Word-Dokumentes.
Das Dokument soll mit dem Inhalt von TextBoxen auf einer Form gefüllt werden. Das klappt von Excel aus sehr gut, ist mir aber nicht "gut" genug. Ich würde es gerne mit VB.Net machen.
Leider fehlt mir hierfür die Erfahrung.
Anbei habe ich den Code von Excel.
Mit dem Button erstelle ich ein neues Dokument.
Private Sub CommandButton1_Click()
Dim appWord As Object
Dim doc As Object
Set appWord = CreateObject("Word.Application")
appWord.Visible = True
Const laufwerk = "Z:\INT\Data\CustomerSolutions\Systems\DE_SY\"
Const ordner = "\1. Projektierung\1.1 Anfrage"
Set doc = appWord.Documents.Add
With doc
'Text im Hauptteil des Dokuments zuweisen
.Range.Text = TextBox15.Text & vbCrLf & _
"Ansprechpartner: " & TextBox14.Text & vbCrLf & _
"Datum: " & Format(Now, "dd.mm.yyyy") & " / " & Format( _
Time, "Short Time") & vbCrLf & _
"Telefon: " & TextBox13.Text & vbCrLf & _
"E-mail: " & TextBox12.Text & vbCrLf & _
"Projektnummer: " & TextBox7.Text & vbCrLf & _
"Angebotsnummer: " & TextBox16.Text & vbCrLf & vbCrLf & _
"Betreff: " & TextBox2.Text & vbCrLf & vbCrLf & vbCrLf _
& _
"Notiz: " & TextBox3.Text
'Kopfzeilen-Text zuweisen
.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = _
"Telefonnotiz vom " & Format$(Now, "Long Date") & "/" & _
TextBox17.Text
'Fusszeilen-Text zuweisen
'.Sections(1).Footers(wdHeaderFooterPrimary).Range.Text = _
' "Erstellt am " & Format$(Now, "Long Date")
End With
'Speicherpfad ermitteln
'##################################################################
Dim X$, Y$, path$, folder$
Dim v As String
Dim v1 As String
Dim speicherpfad As String
Dim Datum As String
Dim Zeit As String
Datum = Format(Date, "yyyy.mm.dd")
Zeit = Format(Time, "hh-mm-ss")
v = TextBox19.Text
v1 = "\" & TextBox18.Text
v = Replace(v, "!", "")
folder = Left(v, 4) + "xx\"
speicherpfad = laufwerk + folder + v + v1 + ordner
'Abfrage speichern
If MsgBox("Notiz speichern unter: " & speicherpfad, vbOKCancel) = _
vbOK Then
doc.SaveAs Filename:=speicherpfad & "/" & Datum & " (" & Zeit & _
") Notiz.doc"
End If
Unload Me
Set doc = Nothing
End Sub Der erste Fehler kommt hier: VB.Net kennt "Date" der "Time" nicht. Was kann ich dafür nehmen?!
Datum = Format(Date, "yyyy.mm.dd")
Zeit = Format(Time, "hh-mm-ss") Mit diesem Codeschnipsel kommt VB.Net aus nicht zurecht.
folder = Left(v, 4) + "xx\" Könnt Ihr mir helfen?! |