1

我是宏的新手。我想编写一个宏来使用 excel 将 MPP 中的列中的特定数据复制到另一个。

我找到了一个代码,可以将数据从一个 excel 复制到另一个。请帮助

Option Explicit

Sub CopytoPS()
    Dim sfil As String
    Dim owbk As Workbook
    Dim sPath As String

    sPath = "C:\Users\HYMC\Excel\Test\" 'Change the file path for your purposes
    sfil = Dir(sPath & "Management Report PS.xls")

    Range("A2:I22").Copy

    Set owbk = Workbooks.Open(sPath & sfil)
    owbk.Sheets("Sales Data").Range("B65536").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
    owbk.Close True 'Save opened workbook and close
    sfil = Dir
End Sub

我想将 MPP 中的某些列复制到 Excel 中的一组列中。我还希望用户只提供目标文件路径、源文件、要复制的源单元格和目标单元格

4

1 回答 1

0

要在 Excel 中使用 MPP 文件,请打开 VBA 编辑器并单击工具菜单上的引用。在可用引用列表中单击以选中 Microsoft Project xx.xx 对象库复选框。如果未列出 Microsoft Project 9.0 对象库,请单击浏览以找到 MsprjXX.olb 文件,该文件位于您安装 Microsoft Project 的文件夹中。默认位置是 C:\Program Files\Microsoft Office\Office。单击“确定”关闭“参考”对话框。然后使用此代码。

由于您没有提到要复制的内容以及确切的位置,因此我将为您提供一个非常基本的代码,然后您可以使用它。

'~~> Code to open MPP file in Excel
Sub Sample()
    Dim appProj As MSProject.Application
    Dim aProg As MSProject.Project
    Dim wb As Workbook
    Dim ws As Worksheet

    Set wb = ActiveWorkbook

    '~~> This is the Sheet Where you want the data to be copied
    Set ws = wb.Sheets("Sheet1")

    Set appProj = CreateObject("Msproject.Application")

    '~~> This is a MS Project File. Change path as applicable.
    appProj.FileOpen "C:\MS Project.mpp"

    Set aProg = appProj.ActiveProject

    appProj.Visible = True

    '~~> Now you have the MPP file opened, rest of the code goes here
End Sub

prerna:你能不能也给我提供学习宏的教程,以在 excel 中使用。这将非常有帮助

您可以访问此链接,这是一个好的开始。但最终,这一切都取决于你练习了多少:)

主题:录制和使用 Excel 宏

链接: http: //office.microsoft.com/en-us/excel-help/record-and-use-excel-macros-HA001054837.aspx

更多关于宏

http://www.excel-vba.com/

http://www.excel-vba-easy.com/

http://www.mrexcel.com/articles.shtml

于 2012-02-19T09:45:50.023 回答