MS Project VBA:尝试将复制的任务从.MPP粘贴到Excel [英] MS Project VBA: Trying to Paste Copied Tasks from .MPP to Excel
问题描述
我正在尝试将任务从MS Project中的特定筛选器复制到Excel文档.这是我到目前为止所拥有的;但是,我无法将任务粘贴到工作簿中.任何帮助都会很棒.
I am trying to copy tasks from a particular filter in MS Project to an Excel document. Here is what I have so far; however, I can't get the tasks to paste to the workbook. Any assistance would be great.
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
推荐答案
EditPaste
是一种Project方法,因此很可能只是复制和过度粘贴相同的内容.
EditPaste
is a Project method so it is likely to be just copying and over-pasting the same content.
此外,Excel中的活动可能会导致复制过程被取消.
Also, activity in Excel could cause the copying process to be cancelled.
向下移动 EditCopy
,并使用 xlSheet.Paste
或Range的 PasteSpecial
方法在Excel中获取内容.
Move EditCopy
further down and use xlSheet.Paste
or the PasteSpecial
method of a Range to get the content in Excel.
'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
EditCopy 'happens in Project
'EditPaste
xlSheet.Paste 'happens in Excel
此外,您可以在粘贴后将标头添加到Excel .这两个步骤不相关.
Additionally, you could add the headers to Excel after pasting. The two steps are not dependent.
这篇关于MS Project VBA:尝试将复制的任务从.MPP粘贴到Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!