时尚的蜡烛 · 首位博士说|莫砺锋:愿在唐诗宋词“仙山秘境” ...· 4 月前 · |
没读研的火柴 · H2内存数据库的函数_h2 call ...· 6 月前 · |
求醉的斑马 · PBI Report Server ...· 1 年前 · |
逼格高的领结 · 《ffmpeg basics》中文版 -- ...· 1 年前 · |
会搭讪的卤蛋 · tp link ...· 1 年前 · |
背景: 我们有一个每周一次的会议,我们都坐在那里,摆出我们的时间表,然后手工地把它们输入到excel主表中。这是不方便、费时和低效的。我们想要使这一过程自动化。
我们需要的: Outlook日历(总计7) ->主Excel表->成员日程表
Outlook需求:
主excel表需要:
成员计划表格:
到目前为止,我制定的代码是:
=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 & ", "
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
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
MsgBox "I could not find a folder named " & varCal & ". Folder skipped. I will continue processing the remaining folders.", vbExclamation + vbOKOnly, SCRIPT_NAME
End If
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
Do While Left(strFolderPath, 1) = "\"
strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
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
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")
我需要“个人”返回一个真正的匹配,只有当它匹配在下划线的COUNTIF中的日期(C3,是与宏表中的D列相匹配的日期)。我只是不知道怎么写。我尝试过一些事情,但一直失败。
我真的需要满足第一和第二逻辑,然后允许满足第三逻辑,以确定它是否正确。因此,第一逻辑和第二逻辑就像一个大过滤器,然后第三个逻辑(以及后面的其他逻辑)将是构成工作表的最终过滤器。
发布于 2017-01-05 16:13:34
我想通了。
我所使用的过程是为了防止有类似问题的人:
我有一张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)
虽然这给了我所需要的数据,但它也给了我更多。例如,如果有人剪了头发,它就会在细胞里“剪”,与那个人和理发日期相对应。
为了弥补这个问题,我又做了一张滤纸。第二张用的是:
=IF(COUNTIF(C5,"**vacation**"),"V",IF(COUNTIF(C5,"**personal**"),"P",IF(COUNTIF(C5,"**half day**"),"Hd","")))
这只是在将outlook导出编入索引的单元格中查找关键字,如果为true,则放置相应的代码。
这让我有了一张V,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