简体   繁体   English

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

[英]how to copy data from mpp file to excel using macro

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复制到另一个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中的某些列复制到Excel中的一组Cloumns中。我还希望用户仅给出目标文件路径,源文件,要复制的源单元格和目标单元格

To work with MPP file in Excel, Open the VBA Editor and click References on the Tools menu. 要在Excel中使用MPP文件,请打开VBA编辑器,然后在“工具”菜单上单击“引用”。 In the Available References list, click to select the Microsoft Project xx.xx Object Library check box. 在“可用引用”列表中,单击以选中“ Microsoft Project xx.xx对象库”复选框。 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. 如果未列出Microsoft Project 9.0对象库,请单击“浏览”以找到MsprjXX.olb文件,该文件位于安装了Microsoft Project的文件夹中。 The default location is C:\\Program Files\\Microsoft Office\\Office. 默认位置是C:\\ Program Files \\ Microsoft Office \\ Office。 Click OK to close the References dialog box. 单击“确定”关闭“引用”对话框。 Then Use this code. 然后使用此代码。

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/zh-cn/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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM