主要问题: 1)如何遍历所有打开的项目 2)如何使其跳过“另存为”中的确定步骤(还有另一种打印到PDF的方法)
当前代码如下:
Dim FirstProject As Project
Dim SecondProject As Project
Dim targetFolder As String
targetFolder =“ C:\ Users \ 522842 \ Desktop \ Community Care Transformation \ 1。可交付成果”
Set FirstProject = ActiveProject
ViewApply Name:="VA Status"
FilterApply Name:="&All Tasks"
FilterApply Name:="Active Tasks"
FilePrint FromPage:=1
FileSaveAs "C:[path here].pdf"
答案 0 :(得分:0)
示例遍历所有打开的项目并导出为PDF格式,保留项目名称并附加“ .PDF”扩展名:
Option Explicit
Sub test()
Dim P As Project
Dim ProjectFullName As String
Dim PDFname As String
Dim DotPos As Integer
For Each P In Projects
P.Activate
'Add code here to apply views and filters as required
ProjectFullName = P.FullName
DotPos = InStr(ProjectFullName, ".")
If DotPos > 0 Then ProjectFullName = Left(ProjectFullName, DotPos - 1)
PDFname = ProjectFullName & ".PDF"
DocumentExport FileName:=PDFname
Next P
End Sub
答案 1 :(得分:0)
我们使它起作用(请注意对用户特定字段的引用,需要对其进行修改。
Sub PrintThisFile()
Dim Names As String
Names = ActiveProject.Name 'Read in file name
Names = Replace(Names, ".mpp", "") 'Get rid of .mpp extension
FilePageSetupPage PaperSize:=pjPaperTabloid
ViewApply Name:="VA Status" 'Set VA Status View
OutlineShowAllTasks
FilterApply Name:="&All Tasks" 'Clears existing filter
FilterApply Name:="Active Tasks" 'Set the Active Filter to prepare the full schedule for printing
DocumentExport FileName:="C:\Users\USERNAME\Desktop\Community Care Transformation\1. Deliverables\" & Names & ".pdf" 'Saves the document as a pdf *MUST CHANGE DESTINATION FOLDER ACCORDINGLY
FilterApply Name:="VA 2 Week" 'Apply the 2 week look ahead view
DocumentExport FileName:="C:\Users\USERNAME\Desktop\Community Care Transformation\1. Deliverables\" & Names & "_Two Week Look Ahead.pdf" 'Saves the 2 week look ahead document as a pdf *MUST CHANGE DESTINATION FOLDER ACCORDINGLY
FilterApply Name:="VA Only Status Due" 'Apply the Only Status Due view
DocumentExport FileName:="C:\Users\USERNAME\Desktop\Community Care Transformation\1. Deliverables\" & Names & "_Due Next Week.pdf" 'Saves the document as a pdf
ViewApply Name:="VA Status" 'Reset to VA Status View
FilterApply Name:="&All Tasks"
FilterApply Name:="Active Tasks"
PaneClose
MsgBox ("Documents have been saved")
End Sub