【发布时间】:2020-07-01 07:08:04
【问题描述】:
我正在尝试将任务从 MS Project 中的特定过滤器复制到 Excel 文档。这是我到目前为止所拥有的;但是,我无法将任务粘贴到工作簿中。任何帮助都会很棒。
Public Sub Export_TopbarToExcel()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim t As Task
Dim pj As Project
Set pj = ActiveProject
Set xlApp = New Excel.Application
xlApp.Visible = True
'applies filter in project
FilterApply Name:="TopBarReport"
'selects filtered tasks and copies them
SelectAll
EditCopy
'adds new workbook
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
'Add the project header info in the top 2 rows
xlSheet.Cells(1, 1).Value = "Status Date"
xlSheet.Cells(1, 2).Value = pj.StatusDate
xlSheet.Cells(1, 3).Value = "Project Title"
xlSheet.Cells(1, 4).Value = pj.Title
'here is where the issue is...it is not pasting the selected info here
xlSheet.Activate
Range("A3").Activate
EditPaste
MsgBox "Done", vbInformation
End Sub
【问题讨论】:
-
发生了什么,或者没有发生什么?有错误吗?
-
没有任何东西粘贴到 excel 文档中。添加了状态日期和项目标题并选择了单元格 A3,但没有粘贴任何内容。如果我在excel中手动“粘贴特殊文本”,信息就会转移。
-
在代码中将 EditCopy 语句进一步向下移动,也许 Excel 中的所有活动都会导致复制过程停止。 (当在单元格中键入内容时,这会直接在 Excel 中发生。)或者在粘贴后添加项目标题。
-
实际上,EditPaste 正在处理 Project。它可能只是复制过度粘贴相同的内容。您可能想要
xlSheet.Paste或 range.PasteSpecial。
标签: excel vba ms-project