对当前 Excel 文件应用强大的自动化流程

问题描述 投票:0回答:1

我使用一个通过报告生成器生成 Excel 报告的程序。 我想在报告模板中插入一个按钮来触发 Power Automate 流程,将部分报告日期传输到 Dataverse。问题是每个 Excel 报表的 Excel 文件名都不同。有没有一种方法可以在当前 Excel 文件上应用触发的 Power Automate 流程,而不是在 Power Automate 中预先指定一个文件?

excel power-automate
1个回答
0
投票

Private WithEvents inboxItems As Outlook.Items

Private Sub Application_Startup()
    Dim outlookApp As Outlook.Application
    Dim inboxFolder As Outlook.Folder
    
    Set outlookApp = Outlook.Application
    Set inboxFolder = outlookApp.Session.GetDefaultFolder(olFolderInbox)
    Set inboxItems = inboxFolder.Items
End Sub

Private Sub inboxItems_ItemChange(ByVal Item As Object)
    On Error Resume Next
    
    Dim mailItem As Outlook.MailItem
    
    If TypeOf Item Is Outlook.MailItem Then
        Set mailItem = Item
        
        ' Check if the mail has a color category
        If mailItem.Categories <> "" Then
            ' Extract required information
            Dim subject As String
            Dim senderEmailAddress As String
            Dim receivedTime As Date
            Dim colorCategory As String
            
            subject = mailItem.Subject
            senderEmailAddress = mailItem.SenderEmailAddress
            receivedTime = mailItem.ReceivedTime
            colorCategory = mailItem.Categories
            
            ' Insert the information into Access database
            InsertIntoAccessDatabase subject, senderEmailAddress, receivedTime, colorCategory
        End If
    End If
End Sub

Private Sub InsertIntoAccessDatabase(ByVal subject As String, ByVal senderEmailAddress As String, ByVal receivedTime As Date, ByVal colorCategory As String)
    ' Your code to insert data into Access database goes here
    ' Example:
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    
    ' Assuming you have a table named 'Emails' in your Access database
    Set db = OpenDatabase("C:\Path\To\Your\Database.accdb")
    Set rs = db.OpenRecordset("Emails", dbOpenDynaset)
    
    rs.AddNew
    rs!Subject = subject
    rs!SenderEmailAddress = senderEmailAddress
    rs!ReceivedTime = receivedTime
    rs!ColorCategory = colorCategory
    rs.Update
    
    rs.Close
    Set rs = Nothing
    db.Close
    Set db = Nothing
End Sub

© www.soinside.com 2019 - 2024. All rights reserved.