#1
|
|||
|
|||
Probleme beim Zugriff auf eingefügtes Dropdownfeld
Hallo zusammen,
bin etwas neu in VBA, soll aber in der Ausbildung ein Script schreiben, welches beim drücken auf einen Button den ausgewählten Wert aus einem Dropdownfeld nimmt und in eine Email pakt. Das Dropdownfeld wird aber mittels einem Vorlagensystem "Docunize" eingefügt. Das folgende Script nutzt aber immer den voreingestellten Wert und nicht den aktuell ausgewöhlten Wert. Hat jemand Ideen? Code:
Sub cmdVersenden_Click() Dim comboBox As ContentControl Dim wert As String Set comboBox = ThisDocument.SelectContentControlsByTitle("PersonalNumber")(1) If Not comboBox Is Nothing Then If comboBox.Type = wdContentControlComboBox Then wert = comboBox.Value MsgBox "Der Inhalt des Dropdown-Felds wurde in die Variable kopiert: " & wert Else MsgBox "Das ausgewählte Formularfeld ist kein ComboBox-Feld." End If Else MsgBox "Das ComboBox-Formularfeld wurde nicht gefunden." End If Dim OutlookApp As Object Dim OutlookMail As Object Set OutlookApp = CreateObject("Outlook.Application") Set OutlookMail = OutlookApp.CreateItem(0) TmpDOC = FindTemp() & "Dokument_Betrieb.doc" ActiveDocument.SaveAs FileName:=TmpDOC, FileFormat:=wdFormatDocument, _ LockComments:=False, Password:="", AddToRecentFiles:=True, _ WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _ SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False With OutlookMail .Subject = "Dokument- Betriebs-Personal - " & wert .To = "interne.Email@Betrieb.de" .Body = "Sehr geehrte Damen und Herren," & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "anbei ein Dokument vom Betrieb" & Chr(13) & Chr(10) & Chr(13) & Chr(10) .Attachments.Add TmpDOC ' Dokument als Anhang anfügen .Display ' E-Mail anzeigen (nicht senden) End With End Sub Wäre für hilfreiche Antworten Dankbar. PS: ChatGPT gibt auch nichts funktionierendes raus MFG Timo |
#2
|
|||
|
|||
I would be very surprised if your code works at all given that it doesn't compile.
Code:
wert = comboBox.Value Code:
wert = comboBox.Range.Text
|
#3
|
|||
|
|||
Hi,
It was my mistake. I have always worked with comboBox.Range.Text. But it always gives me only the text selected in the template, not the one I selected in the form. Is there any other way to read it out? MFG Timo |
#4
|
|||
|
|||
What do you mean by "form"? A UserForm?
|
#5
|
|||
|
|||
I mean a formula that the user fill in. And send it with the button to an Email Adress
|
#6
|
|||
|
|||
I do not understand what you mean by "a formula that the user fill in".
Where does the user fill this in? Where is the button they click? If you add some screenshots it will help our understanding. |
#7
|
|||
|
|||
Here is a Picture from the formula
The first circle is the Dropdownfield (Title: PersonalNumber) The scond is the button to snd this document to an internal Email https://drive.google.com/file/d/1AJ916GabR4clQ7pYf99Er8Wpa0KfzptC/view?usp=share_link |
#8
|
|||
|
|||
It is not possible to tell from your screenshot what the item is, but it is possibly a content control that is showing its prompt text, i.e. no value has been selected. You can check for this by modifying your code:
Code:
If Not comboBox Is Nothing Then If comboBox.Type = wdContentControlComboBox Then If comboBox.ShowingPlaceholderText Then 'no value has been selected Else: wert = comboBox.Range.Text End If |
#9
|
|||
|
|||
Here is a screenshot of the dropdown field that will be inserted and that I want to access
Forum2.png - Google Drive |
#10
|
|||
|
|||
The screenshot confirms what I wrote in post #8
|
#11
|
|||
|
|||
Yes, but it still doesn't work. It always takes the value "Please select a person" in the form, which is preset in the template. It does not take the value that was selected in the form. Is there any other way to read it other than using "comoBox.Range.Text"?
|
#12
|
|||
|
|||
Sorry, I had overlooked that you had used "ThisDocument" to set the object variable. "ThisDocument" refers to the document, or template, that contains the code. Change:
Code:
ThisDocument.SelectContentControlsByTitle("PersonalNumber")(1) Code:
ActiveDocument.SelectContentControlsByTitle("PersonalNumber")(1) |
#13
|
|||
|
|||
Sorry for the late reply, unfortunately the programme has not been running for a long time. It has only been running again recently.
Thanks for the hint. That made it work. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
outlook löscht beim Abruf gemeinsamer imap Emalemail auf dem server | kleinermax | Outlook | 0 | 12-20-2019 04:26 AM |