Err Msg: "Command Could Not Be Completed..." Opening File

Q113269


The information in this article applies to:


SYMPTOMS

In Project, when you use the FileOpen method in a macro to open a file, you receive the following error message if the file is already open:

Run-time error '1004':

Command could not be completed successfully


WORKAROUND

To avoid receiving this error message when you use the FileOpen method to open a project file, you can use the following method as an example:


   Sub Open_File()
      Dim i As Integer
      Dim Filename As String
      Dim filefound As Boolean
      ' Filename string must be in all capitals
      ' Replace following line with desired path and filename
      Filename = "C:\WINPROJ\TEST.MPP"
      ' Check window name of each open project
      For i = 1 To Windows.Count
         ' Check window name against Filename
         If InStr(Filename, Windows(i).Caption) <> 0 Then
            ' If project is already open, activate the window
            Windows(i).Activate
            Filefound = True
         End If
      Next I
      ' If the project was not found as an open window, open the project
      If Not Filefound Then FileOpen Name:=Filename
   End Sub 
Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose. Note that a line that is preceded by an apostrophe introduces a comment in the code--comments are provided to explain what the code is doing at a particular point in the procedure. Note also that an underscore character (_) indicates that code continues from one line to the next. You can type lines that contain this character as one logical line or you can divide the lines of code and include the line continuation character.


STATUS

Microsoft has confirmed this to be a problem in the Microsoft products that are listed at the beginning of this article.


MORE INFORMATION

In Microsoft Project, if you open a project using the Open dialog box while the project is already open, the project is activated and no error message appears. However, if you use the FileOpen method in a macro to open a project file, and the project is already open, the project is activated, but you receive an error message.

Steps to Reproduce Behavior

  1. In a new project, enter a task, T1.


  2. From the File menu, choose Save. In the File Name box, type Test and choose OK.


  3. From the Tools menu, choose Macros. Choose the New button. In the Macro Name box, type Open_File. Choose the Options button. Under Store Macro In, select the Current Project File option and choose OK.


  4. In the new macro, enter the following:


  5. 
          Sub Open_File
             FileOpen Name:="TEST.MPP"
          End Sub 
  6. From the File menu, choose New. From the Tools menu, choose Macros. From the Macro Name list, select Open_File, and then choose Run.


TEST.MPP is activated, but you receive the following error message:
Run-time error '1004':

Command could not be completed successfully


REFERENCES

For more information about the FileOpen method, choose the Search button in Help and type:

FileOpen

Additional query words:

Keywords :
Issue type : kbbug
Technology : kbHWMAC kbOSMAC kbProjectSearch kbProject400Mac kbProjectMacSearch kbProject400


Last Reviewed: November 5, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.