Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Word 2010 VBA Vorlage bauen - HILFE

Empfohlene Antworten

Veröffentlicht

Hallo allle zusammen,

ich brauche ein kleinen Denkanstoß oder eine Idee. Also ich will folgendes bauen:

1. Eine Word-Vorlage

2. Diese Vorlage ist mit Eingabefelder gefüllt die der Bearbeiter auszufüllen hat - egal

3. An der linken Seite des Dokuments ist ein Textfeld wo drin steht "Ausfertigung für den blabla" (Das soll einmal gedruckt werden)

4. Jetzt soll direkt nachdem Drucken das Textfeld automatisch geändert werden in "Ausfertigung für blabla2" und dann muss wieder ausgedruckt werden.

5. Und das ganze nocheinmal. Und dann Fertig.

Zum Schlüss möchte ich dann gerne 3 Ausfertigungen haben mit unterschiedlichen Seitenbeschriftungen.

Ich habe schon mal ein bisschen per VBA rum probiert aber so wirklich will es noch nicht klappen. Die erste Seite kommt richtig raus, die zweite Seite ist dann gleich der ersten Seite. Und die letzte Seite ist dann wieder richtig.

Hier mal mein Quellcode:

ThisDocument:


Option Explicit


Dim oAppClass As New ThisApplication


Private Sub Document_New()

    Set oAppClass.oApp = Word.Application

End Sub

ThisApplication:

Option Explicit


Public WithEvents oApp As Word.Application


Public Function fnWait(intNrOfSeconds As Integer)

Dim varStart As Variant

  varStart = Timer

  Do While Timer < varStart + intNrOfSeconds

  Loop

End Function


Private Sub oApp_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)


ActiveDocument.Shapes(1).Select

Selection.TypeText ("Ausfertigung für 1234 ")

ThisDocument.PrintOut Background:=False, Copies:=1


fnWait (3)


ActiveDocument.Shapes(1).Select

Selection.TypeText ("Ausfertigung für 1234567 ")

ThisDocument.PrintOut Background:=False, Copies:=1


End Sub

Irgendjemand eine Idee?

Vielen Dank für eure Hilfe.

Gruss

Osiris1337

Hallo,

danke für deine Antwort. Leider funktioniert es nicht so einfach. Wenn ich 3mal einen PrintOut mache dann habe ich am Ende 4 Ausdrucke mit 3mal dem gleichen Seitenrand und die letzte Seite ist meistens richtig. Was dann noch hinzukommt wenn das Formular gefüllt ist dann ist auch nur auf der letzten Seite der Inhalt zu sehen alle anderen Ausdrucke davor sind leer.

Ich würde das nicht mit dem DocumentsbeforePrint machen. Schreib ne eigene Sub. Hast du das Updaten der Felder vorm Druck aktiviert? Oder den Dokumentschutz gesetzt/nicht gesetzt?

Rand ändern - Printout - Rand ändern - Printout - Rand ändern - Printout

Wenn das in einer Sub ist sollte das ohne größere Probleme funktionieren. Dann noch nen Makro-Button in nen Ribbon rein und los gehts.

Option Explicit


Public Function fnWait(intNrOfSeconds As Integer)

Dim varStart As Variant

  varStart = Timer

  Do While Timer < varStart + intNrOfSeconds

  Loop

End Function


Sub PrintDoc()


ThisDocument.PrintOut Background:=False, Copies:=1


ActiveDocument.ContentControls(1).Range.Text = "Ausfertigung für 1234 "

ThisDocument.PrintOut Background:=False, Copies:=1


fnWait (3)


ActiveDocument.ContentControls(1).Range.Text = "Ausfertigung für 1234567 "

ThisDocument.PrintOut Background:=False, Copies:=1


End Sub

Das makro druckt einmal das originale Dokument aus, verändert dann das 1. Textfeld, druckt aus, verändert und druckt wieder. Somit solltest auf deine 3 Drucke mit 3 unterschiedlichen Inhalten kommen.

  • 1 Monat später...

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.