views:

32

answers:

0

I recorded a temporary macro in VS2008, in order to find out how to open a particular document so I can then edit it.

Unfortunately, the macro doesn't work when run.

I am guessing that this is because the macro works with the DTE.ActiveWindow object, and when I recorded the macro this is different than when the macro is re-run.

When recording, I opened the file from the solution explorer, so perhaps the ActiveWindow being manipulated here needs to be the solution explorer.

Later when I run the macro, the ActiveWindow is the currently open code window. The macro then fails because the Object doesnt implement GetItem.

How do I go about fixing this macro to get it to work? Perhaps I can set the ActiveWindow to the solution explorer programmatically, or open the file in some other way.

' open the document I want to edit
DTE.ActiveWindow.Object.GetItem(
  "solutionname\projectname\Properties\Resources.resx\Resources.Designer.cs")
    .Select(vsUISelectionType.vsUISelectionTypeSelect)

DTE.ActiveWindow.Object.DoDefaultAction()
DTE.Windows.Item("Resources.Designer.cs").Activate()
' start editing it...
DTE.ActiveDocument.Selection.EndOfDocument()
DTE.ActiveDocument.Selection.LineUp(False, 2)
'etc...