[英]Export Query from Access to an Excel Template
我有一個查詢,它在一周的指定日期運行。 在這一天,如果任何記錄都標記為“需要訂購”,則訂單窗體窗口將打開並帶有命令按鈕。 命令按鈕應將查詢數據導出到excel模板(已經格式化為外觀),然后附加到電子郵件模板進行發送。 我可以將查詢附加到電子郵件,但似乎無法弄清楚如何使用excel模板而不是每次創建新的excel工作簿。 有什么建議可以嘗試嗎?
Dim myolapp As Object
Dim myitem As Object
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "BoxOrder", "C:\Users\Database Design\Desktop\BoxOrder.xlsx", True
Set myolapp = CreateObject("Outlook.Application") myolapp.Session.Logon
Set myitem = myolapp.CreateItemFromTemplate("F:\BOX ORDER FOR PC CONNECTION.oft")
Set myAttachments = myitem.attachments
myAttachments.Add "C:\Users\Database Design\Desktop\BoxOrder.xlsx"
myitem.Display 'or send
DoCmd.Close acForm, "OrderForm"
BoxOrder
查詢:
SELECT '' AS [Quantity Needed], [BoxOrder].[Box Size], [BoxOrder].Comments,
[BoxOrder].[Certified/Stamped Boxes], [BoxOrder].[Box Type]
FROM BoxOrder;
你不能 DoCmd.OutputTo
的TemplateFile
參數僅用於HTML(及類似)導出。
使用DoCmd.OutputTo
或DoCmd.TransferSpreadsheet
之后,有兩種可能性。 這一切都可以通過VBA完成:
這取決於模板的復雜程度,哪個更好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.