none
The trackrevisions method or property is not available because this command is not available for reading. RRS feed

  • Question

  • Hi all,

    I hope someone can help me. I am a programing it in C#. When I use this track revisions funcion, I meet a exception message whose content is the trackrevisions method or property is not available because this command is not available for reading.

    I seach some document but I have not any solution. Could you help me? thanks.

    Word.Document document = null;

    Word.Application wordApp = new Word.Application();

    wordApp.Visible = true;

    Word.Document wordDoc = word.Documents.Open((object)docName);

    wordDoc.Activate();

    oDocument = wordDoc;

    oDocument.Activate(); oDocument.TrackRevisions = true;





    • Edited by Lion-Lars Tuesday, May 19, 2020 5:57 AM
    Friday, May 8, 2020 7:47 AM

All replies

  • 1. Setting document = null, then trying to set its properties doesn't make any sense. Maybe you didn't post the code you actually have.

    2. This message usually indicates that the document is in the "Read Mode" view. If your document variable is actually a reference to a valid document, you may be able to get it out of "Read Mode" using

    document.ActiveWindow.View.ReadingLayout = False
    

    (3. "Read Mode" is a different thing from when you open a document that is "read only".)


    Peter Jamieson

    Saturday, May 9, 2020 3:17 PM
  • Hi, I have updated code in origin code.Could you check again?
    Tuesday, May 19, 2020 4:40 AM
  • If you are still getting the problem, I still think the answer is to adpat and usee the piece of code I suggested. Here is a simple C# console app that I used to test that idea. Maybe it will help:

    using Word=Microsoft.Office.Interop.Word;
    using System;
    
    namespace ConsoleApp1
    {
        class Program
        {
    
            [STAThread]
            static void Main(string[] args)
            {
                //Create an instance for word app  
                Word.Application wordApp = new Word.Application();
                //Set status for word application is to be visible or not.  
                wordApp.Visible = true;
    
                //Open a new document  
                Word.Document document = wordApp.Documents.Open("G:\\test\\2017062901 split names\\datadoc1.docx", false);
                document.Activate();
                string s = "Value of 'document.ActiveWindow.View.ReadingLayout': " + document.ActiveWindow.View.ReadingLayout.ToString();
                Console.WriteLine(s);
                Console.WriteLine("Trying to set TrackRevisions to true");
                try
                {
                    document.TrackRevisions = true;
                    Console.WriteLine("Successfully set TrackRevisions to true");
                }
                catch 
                {
                    Console.WriteLine("Could not set TrackRevisions to true");
                }
    
                if (document.ActiveWindow.View.ReadingLayout != true)
                {
                    Console.WriteLine("Trying to set ReadingLayout to true");
                    try
                    {
                        document.ActiveWindow.ActivePane.View.ReadingLayout = true;
                        Console.WriteLine("Successfully set ReadingLayout to true");
                        Console.WriteLine("Trying to set TrackRevisions to true");
                        try
                        {
                            document.TrackRevisions = true;
                            Console.WriteLine("Successfully set TrackRevisions to true");
                        }
                        catch
                        {
                            Console.WriteLine("Could not set TrackRevisions to true");
                        }
    
                    }
                    catch
                    {
                        Console.WriteLine("Could not set ReadingLayout to true");
                    }
    
                }
                //Wait for user response to the terminal
                Console.ReadKey();
    
            }
        }
    }

    I don't use C# much and am definitely not an expert, but looking at your code, I'd make the following comments...

    This line...

    Word.Document document = null;

    ...creates a variable called Word.Document then immediately sets it to null. You just don't need it IMO, because you create the variable you need below.

    In this line...

    Word.Document wordDoc = word.Documents.Open((object)docName);

    ...you correctly declare and initialise wordDoc.

    So wordDoc is the variable you need to continue using. So you don't need this line...

    oDocument = wordDoc;

    (for that to compile you must have a declaration somewhere that's not in the code you posted.)


    Peter Jamieson

    Wednesday, May 20, 2020 4:36 PM