如何使用宏将mpp文件中的数据复制到Excel

发布于 2025-01-06 19:35:58 字数 688 浏览 2 评论 0 原文

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

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

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

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

熊抱啵儿 2025-01-13 19:35:58

要在 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

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.

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

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

Link: 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-easy.com/

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文