none
Project to excel - vba - 1004 Application-defined or object-defined error RRS feed

  • Question

  • Hi all,

    I am trying to move my task data from Project to Excel and after a lot of editing I am finally close to my goal. However, I am stuck on the last couple of road blocks. For some reason I get the "1004 - Application-defined or object-defined error" when I run the code below. What's weird is that is the ".LeftFooter..." line runs properly whereas the orientation line gives me the error. Both leftfooter and orientation are properties of the same page setup object so its funny that I can access some of the properties and not others?

    With xlApp.ActiveSheet.PageSetup .LeftFooter = Format(Now(), "mm/dd/yy") .Orientation = xlLandscape End With

    My second issue is the same error when I run the code below:

    With xlApp.ActiveSheet
            For i = 1 To .VPageBreaks.count
                .VPageBreaks(i).DragOff Direction:=xlToRight, RegionIndex:=1
            Next i
    End With

    I would greatly appreciate any help!
    Tuesday, May 21, 2013 11:24 PM

Answers

  • yayo84,

    The problem is caused by not having a reference set for the Excel Object Library. In the VB Editor window for Project go to Tools/References and find something like, Microsoft Excel XX.X Object Library. Check it.

    When accessed from a macro running in Project most of Excel's library objects are available even without setting a reference but for some reason, some Excel properties and methods will only work if the reference is set.

    Hope this helps.

    John


    • Edited by John - Project Wednesday, May 22, 2013 1:56 AM
    • Marked as answer by yayo84 Wednesday, May 22, 2013 2:03 AM
    Wednesday, May 22, 2013 1:18 AM

All replies

  • yayo84,

    The problem is caused by not having a reference set for the Excel Object Library. In the VB Editor window for Project go to Tools/References and find something like, Microsoft Excel XX.X Object Library. Check it.

    When accessed from a macro running in Project most of Excel's library objects are available even without setting a reference but for some reason, some Excel properties and methods will only work if the reference is set.

    Hope this helps.

    John


    • Edited by John - Project Wednesday, May 22, 2013 1:56 AM
    • Marked as answer by yayo84 Wednesday, May 22, 2013 2:03 AM
    Wednesday, May 22, 2013 1:18 AM
  • works!...John u have a solution to all my Project problems haha!
    Wednesday, May 22, 2013 2:03 AM
  • yayo84,

    Of course it works, but alas, I do not have a solution to all your Project problems.

    John

    Wednesday, May 22, 2013 3:03 PM