vba 如何使用宏将数据从mpp文件复制到excel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9347874/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 15:16:23  来源:igfitidea点击:

how to copy data from mpp file to excel using macro

excel-vbams-projectvbaexcel

提问by coder25

I am new to macros.I want to write a macro to copy specific data in columns in MPP to another using excel.

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

I have found a code that will copy data from one excel to another.please help

我找到了一个代码,可以将数据从一个 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

I want to copy certain coloums in MPP to a set of cloumns in Excel.I also want user to just give the destination file path,source file ,source cells to be copied and destination cells

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

采纳答案by Siddharth Rout

To work with MPP file in Excel, Open the VBA Editor and click References on the Tools menu. In the Available References list, click to select the Microsoft Project xx.xx Object Library check box. If the Microsoft Project 9.0 Object Library is not listed, click Browse to locate the MsprjXX.olb file, which is in the folder where you have Microsoft Project installed. The default location is C:\Program Files\Microsoft Office\Office. Click OK to close the References dialog box. Then Use this code.

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

Since you have not mentioned what you want to copy and where exactly, i will give you a very basic code which you can then work on.

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

'~~> 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: Can u also provide me the tutorial to learn macros to be used in excel.It would be very helpful

prerna:你能不能也给我提供学习在excel中使用的宏的教程。它会很有帮助

You can visit this link which is a good start. But ultimately, it all depends on how much you practice :)

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

Topic: Record and use Excel macros

主题:记录和使用 Excel 宏

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

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

More On Macros:

更多关于宏

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

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

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

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

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

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