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.

VBA Wenn TextBox gefüllt, dann mache mir...

Empfohlene Antworten

Veröffentlicht

Hallo cummunity :)

ich habe ein kleines Problem:

Am Anfang einer Word Datei von mir kommt eine UserForm in der ein Vorwort geladen werden kann, bei dem klick auf den Button 'Vorwort öffnen' kann eine Datei ausgewählt werden, diese wird mit einem Klick auf 'Datei einbinden' geöffnet, deren Inhalte kopiert und dann wieder geschlossen. Nun springt er wieder in mein Worddokument fügt den Text ein und fertig. Das alles funktioniert.

Möchte ich nun allerdings gar keine Datei mit einbinden, so soll er mir diesen Schritt überspringen, indem er abfragt, ob in einer TextBox die ich angelegt habe, deren Aufgabe es einzig und allein ist die Pfad-Angabe zu machen (der ausgewählten Vorwort-Datei) Text steht.

Das ist mein Code:


[COLOR="Blue"]Private Sub[/COLOR] ButtonVorwort_öffnen_Click()

[COLOR="DarkGreen"]'

' Button der bei Klick ein Vorwort öffnet

'

'


' Dialog zum öffnen einer Worddatei die ein Vorwort enthält[/COLOR]

[COLOR="Blue"]With[/COLOR] Dialogs(wdDialogFileOpen)

.Name = "*.*"

[COLOR="Blue"]If [/COLOR].Display [COLOR="Blue"]Then[/COLOR]

PathAndFileName_Vorwort = WordBasic.FileNameInfo(.Name, 1)

[COLOR="Blue"]End If

End With[/COLOR]

[COLOR="Blue"]If[/COLOR] PathAndFileName_Vorwort = "" [COLOR="Blue"]Then Exit Sub[/COLOR]


[COLOR="DarkGreen"]' Pfadangabe der Worddatei in einer Textbox[/COLOR]

Pfad_gewähltes_Vorwort.Text = PathAndFileName_Vorwort


PfadVorwort = Pfad_gewähltes_Vorwort.Text


[COLOR="Blue"]End Sub[/COLOR]

Und ich will jetzt sagen Wenn Path_gewähltes_Vorwort.Text mit Text gefüllt ist, dann mache mir das:

[COLOR="DarkGreen"]' Word-Vorwort Dokument öffnen[/COLOR]

    Documents.Open FileName:=Pfad_gewähltes_Vorwort.Text, _

        ConfirmConversions:=[COLOR="Blue"]False[/COLOR], ReadOnly:=[COLOR="Blue"]False[/COLOR], AddToRecentFiles:=[COLOR="Blue"]False[/COLOR], _

        PasswordDocument:="", PasswordTemplate:="", Revert:=[COLOR="Blue"]False[/COLOR], _

        WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _

        wdOpenFormatAuto, XMLTransform:=""



[COLOR="DarkGreen"]' Gesamten Inhalt des Vorwortes kopieren und in anderes Dokument einfügen[/COLOR]

    Selection.WholeStory

    Selection.Copy

    ActiveWindow.Close

    Windows("SAP_Workflow_Dokumentation_iXLOG").Activate

        Selection.PasteAndFormat (wdPasteDefault)

Ich hoffe, ich konnte mich leicht genug ausdrücken^^

Vielen lieben dank unf freundliche Grüße aus Hofheim

Julia

Bearbeitet von clusters

Das sollte klappen:


If Len(Path_gewähltes_Vorwort.Text) > 0 Then

	' Word-Vorwort Dokument öffnen

	Documents.Open FileName:=Pfad_gewähltes_Vorwort.Text, _

	ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _

	PasswordDocument:="", PasswordTemplate:="", Revert:=False, _

	WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _

	wdOpenFormatAuto, XMLTransform:=""


	' Gesamten Inhalt des Vorwortes kopieren und in anderes Dokument einfügen

	Selection.WholeStory

	Selection.Copy

	ActiveWindow.Close

	Windows("SAP_Workflow_Dokumentation_iXLOG").Activate

	Selection.PasteAndFormat (wdPasteDefault)

Else

	' If no characters entered...

End If

Gruss,

tester2k5

vielen, vielen dank für deine antwort tester2k5 :)

ich hab das so geregelt:


[COLOR="Blue"]If[/COLOR] [COLOR="Indigo"]Pfad_gewähltes_Vorwort.Text <> ""[/COLOR] [COLOR="Blue"]Then[/COLOR]

[COLOR="DarkGreen"]' Word-Vorwort Dokument öffnen[/COLOR]

    Documents.Open FileName:=Pfad_gewähltes_Vorwort.Text, _

        ConfirmConversions:=[COLOR="Blue"]False[/COLOR], ReadOnly:=[COLOR="Blue"]False[/COLOR], AddToRecentFiles:=[COLOR="Blue"]False[/COLOR], _

        PasswordDocument:="", PasswordTemplate:="", Revert:=[COLOR="Blue"]False[/COLOR], _

        WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _

        wdOpenFormatAuto, XMLTransform:=""



[COLOR="DarkGreen"]' Gesamten Inhalt des Vorwortes kopieren und in anderes Dokument einfügen[/COLOR]

    Selection.WholeStory

    Selection.Copy

    ActiveWindow.Close

    Windows("SAP_Workflow_Dokumentation_iXLOG").Activate

        Selection.PasteAndFormat (wdPasteDefault)

[COLOR="Blue"]End If[/COLOR]

trotzdem nochmal ein danke für deine mühe und viele liebe grüße :)

Julia

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.