Vai al contenuto principale

Come riempire automaticamente l'oggetto dell'e-mail con il nome dell'allegato in Outlook?

Per coloro che sono abituati a utilizzare il nome dell'allegato come oggetto di un'e-mail in Outlook, digitare manualmente il nome dell'allegato nella riga dell'oggetto ogni volta richiederà molto tempo. Come mostrato nella gif di seguito, se desideri riempire automaticamente la riga dell'oggetto dell'e-mail con il nome dell'allegato quando inserisci un allegato, il metodo VBA in questo tutorial ti aiuterà.


Riempi automaticamente l'oggetto dell'e-mail con il nome dell'allegato con il codice VBA

Eseguire il seguente codice VBA per riempire automaticamente l'oggetto dell'e-mail con il nome dell'allegato inserito in Outlook.

1. Avvia Outlook, premi il pulsante altro + F11 chiavi per aprire il Microsoft Visual Basic, Applications Edition finestra.

2. Nel Microsoft Visual Basic, Applications Edition finestra, fare doppio clic Progetto1 (VbProject.OTM) > Oggetti di Microsoft Outlook > Questa sessione di Outlook per aprire il ThisOutlookSession (codice) editore.

3. Quindi copia il seguente codice VBA in ThisOutlookSession (codice) editore.

Codice VBA: compila automaticamente l'oggetto dell'e-mail con il nome dell'allegato

Public WithEvents GExplorer As Explorer
'Updated by Extendoffice 20220926
Public WithEvents GInspectors As Inspectors
Public WithEvents GMail As MailItem

Private Sub Application_Startup()
  Set GExplorer = Application.ActiveExplorer
  Set GInspectors = Application.Inspectors
End Sub

Private Sub GExplorer_InlineResponse(ByVal Item As Object)
  Set GMail = Item
End Sub

Private Sub GInspectors_NewInspector(ByVal Inspector As Inspector)
  Dim xItem As Object
  Set xItem = Inspector.CurrentItem
  If xItem.Class <> olMail Then Exit Sub
  Set GMail = xItem
End Sub

Private Sub GMail_AttachmentAdd(ByVal Att As Attachment)
  Dim xFileName As String
  On Error Resume Next
  If VBA.Trim(GMail.Subject) <> "" Then Exit Sub
  If MsgBox("Do you want to use the attachment name as the subject?", vbYesNo + vbInformation, "Kutools for Outlook") = vbNo Then Exit Sub
  xFileName = Att.DisplayName
  xFileName = Left$(xFileName, VBA.InStrRev(xFileName, ".") - 1)
  GMail.Subject = xFileName
End Sub

4. Ora devi salvare il codice e riavviare Outlook.

5. D'ora in poi, quando si inserisce un allegato in un messaggio di posta elettronica che non ha ancora un oggetto compilato, a Kutools for Outlook verrà visualizzata una finestra di dialogo che ti chiede se desideri utilizzare il nome dell'allegato come oggetto, fai clic su pulsante.

Quindi la riga dell'oggetto verrà popolata automaticamente con il nome dell'allegato inserito.

Note:

1) Se hai già inserito l'oggetto, l'inserimento di un allegato non farà apparire la finestra di dialogo.
2) Se si rimuove un oggetto esistente dall'e-mail corrente ma il cursore è ancora visualizzato nella riga dell'oggetto, l'inserimento di un allegato non farà apparire nemmeno la finestra di dialogo. Dopo aver rimosso l'oggetto, è necessario allontanarsi dalla riga dell'oggetto per aggiornare la finestra del messaggio e far funzionare il codice.
3) Se si inseriscono più allegati contemporaneamente, solo il nome del primo allegato può essere utilizzato come oggetto dell'e-mail.

I migliori strumenti per la produttività in ufficio

Kutools for Outlook - Oltre 100 potenti funzionalità per potenziare il tuo Outlook

🤖 Assistente di posta AI: E-mail istantanee professionali con la magia dell'intelligenza artificiale: risposte geniali con un solo clic, tono perfetto, padronanza multilingue. Trasforma l'e-mail senza sforzo! ...

???? Automazione di posta elettronica: Fuori sede (disponibile per POP e IMAP)  /  Pianifica l'invio di e-mail  /  CC/BCC automatico in base alle regole durante l'invio di e-mail  /  Inoltro automatico (regole avanzate)   /  Aggiunta automatica di saluto   /  Suddividi automaticamente le email con più destinatari in singoli messaggi ...

📨 gestione e-mail: Richiama facilmente le email  /  Blocca le email truffe per soggetto e altri  /  Elimina email duplicate  /  Ricerca avanzata  /  Consolidare cartelle ...

📁 Allegati ProSalvataggio in batch  /  Stacca batch  /  Comprimi in lotti  /  Salvataggio automatico   /  Scollegamento automatico  /  Comprimi automaticamente ...

🌟 Magia dell'interfaccia: 😊Più emoji carini e fantastici   /  Aumenta la tua produttività in Outlook con le visualizzazioni a schede  /  Riduci a icona Outlook invece di chiuderlo ...

👍 Meraviglie con un clic: Rispondi a tutti con gli allegati in arrivo  /   E-mail anti-phishing  /  🕘Mostra il fuso orario del mittente ...

👩🏼‍🤝‍👩🏻 Contatti e calendario: Aggiungi in batch contatti dalle email selezionate  /  Dividere un gruppo di contatti in singoli gruppi  /  Rimuovi promemoria compleanno ...

Al di sopra Caratteristiche 100 Attendi la tua esplorazione! Clicca qui per scoprire di più.

 

 

Comments (11)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Everything works now. Thanks very much.
This comment was minimized by the moderator on the site
I'm glad I could help you.
This comment was minimized by the moderator on the site
Hello,
I pasted your code. Outlook 365 restarted. I've tried several times, but it doesn't work. The subject line remains empty. What could be the problem?
This comment was minimized by the moderator on the site
Hi Karol,

Please check if the corresponding Macro settings are enabled in your Outlook.
Go to File > Options. In the Outlook Options window, select Trust Center in the left pane. In the Trust Center window, select Macro Settings in the left pane, and then select the Enable all macros option in the Macro Settings section and check the Apply macro security settings to installed add-ins box in the Add-ins section.
https://www.extendoffice.com/images/stories/comments/comment-picture-zxm/subject-auto.png
This comment was minimized by the moderator on the site
Добрый день. ДА при добавлении 2 файлов в тему писалось через И.
This comment was minimized by the moderator on the site
Hi Александр,

The following VBA code can help to solve your problem. Please give it a try.
Public WithEvents GExplorer As Explorer
'Updated by Extendoffice 20220131
Public WithEvents GInspectors As Inspectors
Public WithEvents GMail As MailItem
Dim GFileName As String

Private Sub Application_Startup()
  Set GExplorer = Application.ActiveExplorer
  Set GInspectors = Application.Inspectors
End Sub

Private Sub GExplorer_InlineResponse(ByVal Item As Object)
  Set GMail = Item
  GFileName = ""
End Sub

Private Sub GInspectors_NewInspector(ByVal Inspector As Inspector)
  Dim xItem As Object
  Set xItem = Inspector.CurrentItem
  If xItem.Class <> olMail Then Exit Sub
  Set GMail = xItem
  GFileName = ""
End Sub

Private Sub GMail_AttachmentAdd(ByVal Att As Attachment)
  If GMail.Subject = "" Then
    GMail.Subject = GFileName
  Else
    GMail.Subject = GMail.Subject & " AND " & GFileName
  End If
  GFileName = ""
End Sub

Private Sub GMail_BeforeAttachmentAdd(ByVal Attachment As Attachment, Cancel As Boolean)
  On Error Resume Next
  GFileName = Attachment.DisplayName
  GFileName = Left$(GFileName, VBA.InStrRev(GFileName, ".") - 1)
  If VBA.Trim(GMail.Subject) <> "" Then Exit Sub
  If MsgBox("Do you want to use the attachment name as the subject?", vbYesNo + vbInformation, "Kutools for Outlook") = vbNo Then
    GFileName = ""
    Exit Sub
  End If
End Sub
This comment was minimized by the moderator on the site
Да получилось. Огромное спасибо за помощь. И еще один вопрос, а можно в конце всего этого, при нажатии кнопки "Отправить" выдавал некое сообщение что то типа "Вы действительно хотите отправить данное сообщение"?
This comment was minimized by the moderator on the site
Да, именно. ТЕ при добавлении или перетягивании двух файлов тема письма автоматом писалась через И
This comment was minimized by the moderator on the site
Добрый день. Подскажите пожалуйста можно ли сделать что бы тема формировалась из 2 и более файлов с разделение И? Может в данном коде дописать или вообще другой существует? Заранее спасибо
This comment was minimized by the moderator on the site
Hi Александр,

Do you mean adding multiple attachments while adding those attachment names at the same time to the subject and then linking them with AND?
This comment was minimized by the moderator on the site
Да. Например перетащил два файла и он их имена написал через И. Именно два файла, больше не надо.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations