วิธีการสร้างการนัดหมายจากข้อมูล Excel?
สมมติว่าคุณมีตารางข้อมูลการนัดหมายไว้ในแผ่นงาน Excel ดังภาพต่อไปนี้แสดงภาพตอนนี้คุณต้องการนำเข้าข้อมูลเหล่านี้ลงในปฏิทิน Outlook คุณจะรับมือกับงานนี้ได้เร็วแค่ไหน?
สร้างการนัดหมายจากข้อมูล 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 สำหรับแอ็พพลิเคชัน หน้าต่างคลิก เครื่องมือ > อ้างอิง ไป อ้างอิง Project1 กล่องโต้ตอบและตรวจสอบ ไลบรารีวัตถุ Microsoft Excel ตัวเลือกจาก การอ้างอิงที่มีอยู่ กล่องรายการดูภาพหน้าจอ:
4. จากนั้นคลิก OK กดตอนนี้กด F5 คีย์เพื่อเรียกใช้รหัสนี้และ เลือกไฟล์ จะปรากฏขึ้นโปรดเลือกไฟล์ excel ที่คุณต้องการนำเข้าไปยัง Outlook ดูภาพหน้าจอ:
5. จากนั้นคลิก OKกล่องพรอมต์จะปรากฏขึ้นดังต่อไปนี้:
6. จากนั้นคลิก OKข้อมูล Excel ถูกนำเข้ามายังปฏิทินดังภาพต่อไปนี้:
Kutools สำหรับ Outlook
มากกว่าฟังก์ชั่นขั้นสูง 100 สำหรับ Outlook 2010, 2013, 2016, 2019 และ 365
คุณสมบัติอื่น ๆ | ดาวน์โหลดฟรี | เพียง $ 39.00 สำหรับหลายร้อยฟังก์ชัน
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Be the first to comment.