背景 我们每周都有一次会议,我们都会坐下来制定我们的日程安排,然后手动将它们输入到主Excel表格中。这是不方便的,耗时且低效的。我们希望自动化这个过程。
我们需要什么: Outlook日历(共7个) - >主Excel表 - >会员日程表Excel表
Outlook需要:
掌握excel表需要:
会员日程表Excel表格
此excel表格列出了日期和日期的成员列表 月。例如:
我们需要根据来自的标准填写此excel表 掌握excel表
一个。示例:如果Person1的假期定于2017年4月10日至 10月10日,我们需要填写“V”的相应框 excel表格中该人员的日期。
表格需要满足的标准是:
一个。两张表上的事件匹配日期
湾日历的所有者匹配人(必须搜索这个 通过关键字...示例:成员计划表Excel上的最后一个 将在主人上显示为“first.last@email.com \ calendar” excel sheet。)
℃。寻找某些关键词(即“度假”,“persoanl”等......我们 将这些设置在主表单主题框列的内部 确定具体日期和人员是否已加入假期 一天,个人日,半天假期等。这个命令应该填写 在工作表中用适当的符号表示什么类型的 它是
d。如果一个事件包含2个或更多个人,那么该列 应该是黄色的“重大事件/会议”充满了 事件名称
到目前为止,我所做的代码是:
=IF(AND(ISNUMBER(SEARCH("dakota.mccarty",[Macros.xlsx]Sheet1!$A:$A)),(K$3=[Macros.xlsx]Sheet1!$D:$D),(COUNTIF( [Macros.xlsx]Sheet1!$C:$C, "**vacation**"))), $B$15, "0")
此搜索假期是否在主题中并返回“V”
正如你所看到的,它很长而且只有一件事......
这是将Outlook日历带入Excel的代码: 它有效,但没有自动化。
Sub ExportAppointmentsToExcel()
'On the next line, the list of calendars you want to export. Each entry is the path to a calendar. Entries are separated by a comma.
Const CAL_LIST = "user1\Calendar, user2\Calendar, user3\Calendar , etc"
'On the next line, edit the path to and name of the Excel spreadsheet to export to
Const EXCEL_FILE = "c:\users\415085\desktop\Macros\Macros.xlsx"
Const SCRIPT_NAME = "Export Appointments to Excel (Rev 2)"
Const xlAscending = 1
Const xlYes = 1
Dim olkFld As Object, _
olkLst As Object, _
olkRes As Object, _
olkApt As Object, _
olkRec As Object, _
excApp As Object, _
excWkb As Object, _
excWks As Object, _
lngRow As Long, _
lngCnt As Long, _
strFil As String, _
strLst As String, _
strDat As String, _
datBeg As Date, _
datEnd As Date, _
arrTmp As Variant, _
arrCal As Variant, _
varCal As Variant
strDat = InputBox("Enter the date range of the appointments to export in the form ""mm/dd/yyyy to mm/dd/yyyy""", SCRIPT_NAME, Date & " to " & Date)
arrTmp = Split(strDat, "to")
datBeg = IIf(IsDate(arrTmp(0)), arrTmp(0), Date) & " 12:00am"
datEnd = IIf(IsDate(arrTmp(1)), arrTmp(1), Date) & " 11:59pm"
Set excApp = CreateObject("Excel.Application")
Set excWkb = excApp.Workbooks.Add()
Set excWks = excWkb.Worksheets(1)
'Write Excel Column Headers
With excWks
.Cells(1, 1) = "Calendar"
.Cells(1, 2) = "Category"
.Cells(1, 3) = "Subject"
.Cells(1, 4) = "Starting Date"
.Cells(1, 5) = "Ending Date”
.Cells(1, 6) = "Attendees"
End With
lngRow = 2
arrCal = Split(CAL_LIST, ",")
For Each varCal In arrCal
Set olkFld = OpenOutlookFolder(CStr(varCal))
If TypeName(olkFld) <> "Nothing" Then
If olkFld.DefaultItemType = olAppointmentItem Then
Set olkLst = olkFld.Items
olkLst.Sort "[Start]"
olkLst.IncludeRecurrences = True
Set olkRes = olkLst.Restrict("[Start] >= '" & Format(datBeg, "ddddd h:nn AMPM") & "' AND [Start] <= '" & Format(datEnd, "ddddd h:nn AMPM") & "'")
'Write appointments to spreadsheet
For Each olkApt In olkRes
'Only export appointments
If olkApt.Class = olAppointment Then
strLst = ""
For Each olkRec In olkApt.Recipients
strLst = strLst & olkRec.Name & ", "
Next
If strLst <> "" Then strLst = Left(strLst, Len(strLst) - 2)
'Add a row for each field in the message you want to export
excWks.Cells(lngRow, 1) = olkFld.FolderPath
excWks.Cells(lngRow, 2) = olkApt.Categories
excWks.Cells(lngRow, 3) = olkApt.Subject
excWks.Cells(lngRow, 4) = Format(olkApt.Start, "mm/dd/yyyy")
excWks.Cells(lngRow, 5) = Format(olkApt.End, "mm/dd/yyyy")
excWks.Cells(lngRow, 6) = strLst
lngRow = lngRow + 1
lngCnt = lngCnt + 1
End If
Next
Else
MsgBox "Operation cancelled. The selected folder is not a calendar. You must select a calendar for this macro to work.", vbCritical + vbOKOnly, SCRIPT_NAME
End If
Else
MsgBox "I could not find a folder named " & varCal & ". Folder skipped. I will continue processing the remaining folders.", vbExclamation + vbOKOnly, SCRIPT_NAME
End If
Next
excWks.Columns("A:I").AutoFit
excWks.Range("A1:I" & lngRow - 1).Sort Key1:="Category", Order1:=xlAscending, Header:=xlYes
excWks.Cells(lngRow, 8) = "=sum(H2:H" & lngRow - 1 & ")"
excWkb.SaveAs EXCEL_FILE
excWkb.Close
MsgBox "Process complete. I exported a total of " & lngCnt & " appointments were exported.", vbInformation + vbOKOnly, SCRIPT_NAME
Set excWks = Nothing
Set excWkb = Nothing
Set excApp = Nothing
Set olkApt = Nothing
Set olkLst = Nothing
Set olkFld = Nothing
End Sub
Private Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIFolder
Dim arrFolders As Variant, _
varFolder As Variant, _
bolBeyondRoot As Boolean
On Error Resume Next
If strFolderPath = "" Then
Set OpenOutlookFolder = Nothing
Else
Do While Left(strFolderPath, 1) = "\"
strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
Loop
arrFolders = Split(strFolderPath, "\")
For Each varFolder In arrFolders
Select Case bolBeyondRoot
Case False
Set OpenOutlookFolder = Outlook.Session.Folders(varFolder)
bolBeyondRoot = True
Case True
Set OpenOutlookFolder = OpenOutlookFolder.Folders(varFolder)
End Select
If Err.Number <> 0 Then
Set OpenOutlookFolder = Nothing
Exit For
End If
Next
End If
On Error GoTo 0
End Function
如果您有任何其他问题或疑惑,请告诉我,我正在努力解决这个问题。
到目前为止,我有这个:
=IF(AND(ISNUMBER(SEARCH("dakota.mccarty",[Macros.xlsx]Sheet1!$A:$A)),(COUNTIF([Macros.xlsx]Sheet1!$D:$D,C3)),(COUNTIF([Macros.xlsx]Sheet1!$C:$C,"Personal"))),$B$15, "0")
我需要“个人”才能返回TRUE匹配,只有它与带下划线的COUNTIF中的日期相匹配(C3,是与宏表上的D列匹配的日期)。我只是不知道该怎么写。我尝试了一些事情并且一直都在失败。
我确实需要满足第一和第二逻辑然后允许满足第三个逻辑以确定它是否真实。因此,第一个和第二个逻辑就像一个大型过滤器,然后第三个(以及之后的其他逻辑)将是制作表单的最终过滤器。
答案 0 :(得分:0)
我明白了。
我使用的过程以防任何人遇到类似问题:
我有一张使用过的excel表:
=INDEX([CalendarExport.xlsx]Sheet1!$C:$C,MATCH("*first.last*"&C$3,[CalendarExport.xlsx]Sheet1!$A:$A&[nate.xlsx]Sheet1!$D:$D,0))
这将从Outlook导出的数据编入索引,只输入该日历对同一个人和日期的任何内容。 CalendarExport.xlsx中的C:C列是所需的数据(个人,假期等)。
我刚为每个人制定了一个单独的公式。 (不要忘记cntl + shift + enter)
虽然这给了我需要的数据,但它也提供了更多。例如,如果有人理发了它,那就是理发&#34;在与理发人员和理发日期相对应的单元格中。
为了解决这个问题,我制作了另一张经过此过滤的表格。 使用了第二张表:
=IF(COUNTIF(C5,"**vacation**"),"V",IF(COUNTIF(C5,"**personal**"),"P",IF(COUNTIF(C5,"**half day**"),"Hd","")))
这只是在索引outlook导出的单元格中查找关键字,并将相应的代码设置为true。
这使我得到了一张包含V&P,P&P和Hd的表格,没有其他信息。所以,我有我需要的一切。
为了自动将数据转到日历表,我只是做了一个宏来复制它。我不想在主表上有一个公式连接到这个较小的表,因为每周五都会更新和刷新数据,所以如果我使用公式查找文本,那么前一周的数据将被删除细胞需要的。
要从已过滤的日历表中复制数据并将其作为文本(而不是公式)粘贴到主日历表中,我使用了以下内容:
Sub UpdateCalendar()
'
'Update Calendar
'
'Jan to March
Sheets("Calendar(Mechanics)").Activate
ActiveSheet.Range("C16:BO23").Select
Selection.Copy
Sheets("2017").Select
Range("B7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'April to June
Sheets("Calendar(Mechanics)").Activate
ActiveSheet.Range("BP16:EB23").Select
Selection.Copy
Sheets("2017").Select
Range("B19").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'July to September
Sheets("Calendar(Mechanics)").Activate
ActiveSheet.Range("EC16:GO23").Select
Selection.Copy
Sheets("2017").Select
Range("B31").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'October to December
Sheets("Calendar(Mechanics)").Activate
ActiveSheet.Range("GP16:JB23").Select
Selection.Copy
Sheets("2017").Select
Range("B43").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
由于我的主日历设置如何,我不得不复制并粘贴四个单独的块。但是,对我来说没问题。
在主页上,我在顶角放了一个按钮,允许该页面运行宏,以便随时更新。
我仍然需要处理自动化Outlook导出,但对于某些编码和谷歌来说应该不是很难。
祝你好运!