Word keeps attempting to "recover my information"

-1

In my software i'm parsing a powerpoint file for information. however when i need to know if specific words have bolded text it doesn't work very well in powerpoint.

My solution was to open up a word document on the side copy and paste the text over and parse it in word which allows me to check character by character to detect which specific word is bolded.

This works fine but from time to time I'll get a prompt

enter image description here

which will stop the software and trigger the below error

System.Runtime.InteropServices.COMException: 'The remote procedure call failed. (Exception from HRESULT: 0x800706BE)'

sometimes if i just close out word with task manager and restart the software it'll run fine without this coming up and sometimes it'd persist a few more trys before it finally does work.

Does anyone know why this is happening? I've disabled the autosave feature option in Word so it shouldn't be trying to recover any saves.

EDIT:

using Microsoft.Office.Core;
using System;
using System.IO;
using System.Runtime.InteropServices;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Word = Microsoft.Office.Interop.Word;

namespace tempSW
{
    class Program
    {
        public static string FileNameToParse = "";
        public static PowerPoint.Application pptApplication;
        public static PowerPoint.Presentation pptPresentation;

        static void Main(string[] args)
        {
            FileNameToParse = args[0];
            if (OpenPPT())
                ParsePPT();
            else
                Console.WriteLine("Opening Powerpoint file {0} failed.", FileNameToParse); 
        }

        public static bool OpenPPT()
        {
            if (!File.Exists(FileNameToParse))
            {
                Console.WriteLine("File " + FileNameToParse + " does not exist");
                return false;
            }
            else
            {
                pptApplication = new PowerPoint.Application();
                pptPresentation = pptApplication.Presentations.Open(FileNameToParse, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
                return true;
            }
        }

        public static void ClosePPT()
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
            pptPresentation.Close();
            Marshal.FinalReleaseComObject(pptPresentation);
            pptApplication.Quit();
            Marshal.FinalReleaseComObject(pptApplication);
        }

        public static void ParsePPT()
        {
            Word.Application wordDoc = new Word.Application
            {
                ShowAnimation = false
            };
            object missing = System.Reflection.Missing.Value;
            Word.Document doc = wordDoc.Documents.Add(ref missing, ref missing, ref missing, ref missing);
            doc.Content.SetRange(0, 0);

            foreach (PowerPoint.Slide _slide in pptPresentation.Slides)
            {
                foreach (PowerPoint.Shape _shape in _slide.Shapes)
                {
                    if (_shape.HasTextFrame == MsoTriState.msoTrue)
                    {
                        var textFrame = _shape.TextFrame;
                        if (textFrame.HasText == MsoTriState.msoTrue)
                        {
                            var textRange = textFrame.TextRange;
                            textRange.Copy();
                            doc.Content.PasteSpecial(ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                            if (textRange.Font.Bold == MsoTriState.msoTriStateMixed ? true : false)
                                DetectBold(doc);
                        }
                    }

                }
            }
            GC.Collect();
            GC.WaitForPendingFinalizers();
            object saveOption = Word.WdSaveOptions.wdDoNotSaveChanges;
            doc.Close(Word.WdSaveOptions.wdDoNotSaveChanges, ref missing, ref missing);
            Marshal.FinalReleaseComObject(doc);
            wordDoc.Quit(ref missing, ref missing, ref missing);
            Marshal.FinalReleaseComObject(wordDoc);
            ClosePPT();
        }

        private static void DetectBold(Word.Document doc)
        {
            foreach (Word.Paragraph para in doc.Paragraphs)
            {
                Word.Range range = para.Range;
                if (range.Text.Trim() != "")
                {
                    for (int WordPointer = 1; WordPointer < range.Words.Count; WordPointer++) //check each word.
                    {
                        if (range.Words[WordPointer].Bold == -1)
                            Console.WriteLine("{0} is a bolded word", range.Words[WordPointer].Text);
                    }
                }
            }
        }
    }
}
c#
ms-word
interop
powerpoint
office-interop
asked on Stack Overflow Aug 22, 2019 by Eric • edited Aug 22, 2019 by Eric

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0