ไปยังเนื้อหาหลัก

จะสร้างการนัดหมายจากข้อมูล Excel ได้อย่างไร

สมมติว่าคุณมีตารางข้อมูลการนัดหมายในแผ่นงาน Excel ตามภาพหน้าจอต่อไปนี้ตอนนี้คุณต้องการนำเข้าข้อมูลเหล่านี้ไปยังปฏิทิน Outlook คุณจะจัดการกับงานนี้อย่างรวดเร็วได้อย่างไร?

doc ส่งออกข้อมูล excel ไปยังการนัดหมาย 1

สร้างการนัดหมายจากข้อมูล Excel ด้วยรหัส VBA


สร้างการนัดหมายจากข้อมูล Excel ด้วยรหัส VBA

ในการสร้างการนัดหมายจากข้อมูล Excel คุณสามารถใช้รหัส VBA ต่อไปนี้ได้โปรดดำเนินการดังนี้:

1. เปิด Outlook และกดไฟล์ ALT + F11 คีย์เพื่อเปิด Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

2. คลิก สิ่งที่ใส่เข้าไป > โมดูลและวางรหัสต่อไปนี้ในไฟล์ โมดูล หน้าต่าง.

รหัส VBA: นำเข้าข้อมูล excel เพื่อนัดหมาย:

Public Sub CreateOutlookApptz()
    Dim xAppointmentItem As Outlook.AppointmentItem
    Dim xNameSpace As Outlook.NameSpace
    Dim xCalendarFld As Outlook.MAPIFolder, xSubFolder As Outlook.MAPIFolder
    Dim xCalendarStr As String
    Dim I As Long
    Dim xFileDialog As FileDialog
    Dim xFilePath As String
    Dim xExcelApp As Excel.Application
    Dim xWb As Workbook
    Dim xWs As Worksheet
    On Error GoTo Err_Execute
    Set xExcelApp = New Excel.Application
    Set xFileDialog = xExcelApp.FileDialog(msoFileDialogFilePicker)
    With xFileDialog
        .Title = "Select a file"
        .Filters.Add "Microsoft Excel", "*.xlsx"
    End With
    If xFileDialog.Show = 0 Then Exit Sub
    xFilePath = xFileDialog.SelectedItems(1)
    Set xWb = xExcelApp.Workbooks.Open(xFilePath)
    Set xNameSpace = Outlook.Application.Session
    Set xCalendarFld = xNameSpace.GetDefaultFolder(olFolderCalendar)
    I = 2
    Set xWs = xWb.Worksheets.Item(1)
    xCalendarStr = xWb.Name
    If FolderExist(xCalendarFld, xCalendarStr) = False Then
        Set xSubFolder = xCalendarFld.Folders.Add(xCalendarStr, olFolderCalendar)
    Else
        Set xSubFolder = xCalendarFld.Folders(xCalendarStr)
    End If
    Do Until Trim(xWs.Cells(I, 1).Value) = ""
        Set xAppointmentItem = xSubFolder.Items.Add(olAppointmentItem)
        With xAppointmentItem
            .Start = xWs.Cells(I, 5) + xWs.Cells(I, 6)
            .End = xWs.Cells(I, 7) + xWs.Cells(I, 8)
            .Subject = xWs.Cells(I, 1)
            .Location = xWs.Cells(I, 2)
            .Body = xWs.Cells(I, 3)
            .BusyStatus = olBusy
            .ReminderMinutesBeforeStart = xWs.Cells(I, 9)
            .ReminderSet = True
            .Categories = xWs.Cells(I, 4)
            .Save
        End With
        I = I + 1
    Loop
    Set xAppointmentItem = Nothing
    Set olApp = Nothing
    xExcelApp.Quit
    Set xExcelApp = Nothing
    MsgBox "Import successfully!", vbInformation, "Kutools for Outlook"
    Exit Sub
Err_Execute:
    MsgBox "An error occurred - Exporting items to Calendar.", vbInformation, "Kutools for Outlook"
End Sub
Function FolderExist(CalFolder As Folder, FolderName As String) As Boolean
    Dim I As Integer
    Dim xSubFolder As Folder
    For I = 1 To CalFolder.Folders.Count
        Set xSubFolder = CalFolder.Folders.Item(I)
        If xSubFolder.Name = FolderName Then
            FolderExist = True
            Exit Function
        End If
    Next I
End Function

3. ยังคงอยู่ใน Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่างคลิก เครื่องมือ > อ้างอิง ไป เอกสารอ้างอิง - โครงการ 1 กล่องโต้ตอบและตรวจสอบ ไลบรารีวัตถุ Microsoft Excel ตัวเลือกจาก อ้างอิงที่มีอยู่ กล่องรายการดูภาพหน้าจอ:

doc ส่งออกข้อมูล excel ไปยังการนัดหมาย 2

4. จากนั้นคลิก OK ตอนนี้กด F5 กุญแจสำคัญในการเรียกใช้รหัสนี้และไฟล์ เลือกไฟล์ หน้าต่างจะปรากฏขึ้นโปรดเลือกไฟล์ excel ที่คุณต้องการนำเข้าสู่ Outlook ดูภาพหน้าจอ:

doc ส่งออกข้อมูล excel ไปยังการนัดหมาย 3

5. จากนั้นคลิก OKกล่องพร้อมต์จะปรากฏขึ้นดังนี้:

doc ส่งออกข้อมูล excel ไปยังการนัดหมาย 4

6. จากนั้นคลิก OKข้อมูล Excel ถูกนำเข้าสู่ปฏิทินตามภาพหน้าจอต่อไปนี้:

doc ส่งออกข้อมูล excel ไปยังการนัดหมาย 5


สุดยอดเครื่องมือเพิ่มผลผลิตในสำนักงาน

Kutools สำหรับ Outlook - คุณสมบัติอันทรงพลังมากกว่า 100 รายการเพื่อเติมพลังให้กับ Outlook ของคุณ

🤖 ผู้ช่วยจดหมาย AI: ส่งอีเมลระดับมืออาชีพทันทีด้วยเวทมนตร์ AI คลิกเพียงครั้งเดียวเพื่อตอบกลับอย่างชาญฉลาด น้ำเสียงที่สมบูรณ์แบบ การเรียนรู้หลายภาษา เปลี่ยนรูปแบบการส่งอีเมลอย่างง่ายดาย! ...

📧 การทำงานอัตโนมัติของอีเมล: ไม่อยู่ที่สำนักงาน (ใช้ได้กับ POP และ IMAP)  /  กำหนดการส่งอีเมล  /  Auto CC/BCC ตามกฎเมื่อส่งอีเมล  /  ส่งต่ออัตโนมัติ (กฎขั้นสูง)   /  เพิ่มคำทักทายอัตโนมัติ   /  แบ่งอีเมลผู้รับหลายรายออกเป็นข้อความส่วนตัวโดยอัตโนมัติ ...

📨 การจัดการอีเมล์: เรียกคืนอีเมลได้อย่างง่ายดาย  /  บล็อกอีเมลหลอกลวงตามหัวเรื่องและอื่นๆ  /  ลบอีเมลที่ซ้ำกัน  /  การค้นหาขั้นสูง  /  รวมโฟลเดอร์ ...

📁 ไฟล์แนบโปรบันทึกแบทช์  /  การแยกแบทช์  /  การบีบอัดแบบแบตช์  /  บันทึกอัตโนมัติ   /  ถอดอัตโนมัติ  /  บีบอัดอัตโนมัติ ...

🌟 อินเตอร์เฟซเมจิก: 😊อีโมจิที่สวยและเจ๋งยิ่งขึ้น   /  เพิ่มประสิทธิภาพการทำงาน Outlook ของคุณด้วยมุมมองแบบแท็บ  /  ลดขนาด Outlook แทนที่จะปิด ...

???? เพียงคลิกเดียวสิ่งมหัศจรรย์: ตอบกลับทั้งหมดด้วยไฟล์แนบที่เข้ามา  /   อีเมลต่อต้านฟิชชิ่ง  /  🕘 แสดงโซนเวลาของผู้ส่ง ...

👩🏼‍🤝‍👩🏻 รายชื่อและปฏิทิน: แบทช์เพิ่มผู้ติดต่อจากอีเมลที่เลือก  /  แบ่งกลุ่มผู้ติดต่อเป็นกลุ่มแต่ละกลุ่ม  /  ลบการแจ้งเตือนวันเกิด ...

เกิน คุณสมบัติ 100 รอการสำรวจของคุณ! คลิกที่นี่เพื่อค้นพบเพิ่มเติม

 

 

Comments (3)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Returns "Compile error: User-defined type not defined"
This comment was minimized by the moderator on the site
Hello,

Thank you so much but the code is not executing successfully when creating appointments in a shared calendar. Could you please help
This comment was minimized by the moderator on the site
super cool il ya une erreur je la i rectifier mai apparament mes items colle pas mince



olApp = Nothing ?
xExcelApp.Quit
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations