Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Close wrod corrctly, it's possile?

Close wrod corrctly, it's possile?

Scheduled Pinned Locked Moved C#
comsysadminquestion
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abbd
    wrote on last edited by
    #1

    Hello, I create 4000 files word like this :

    foreach (string s in FUSIONSS_1)
    {

                String\[\] tbStr2 = s.Split(new Char\[\] { ';' });
                string nb = tbStr2\[0\];
                Object oMissing = System.Reflection.Missing.Value;
                Object oTrue = true;
                Object oFalse = false;
                Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
                Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
                oWord.Visible = true;
                oWord.Visible = false;
                Object oTemplatePath = modelee;
                oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
                bool sympb = false; bool E = false; bool n = false; bool p = false; bool r = false;
               
                foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
                {if (range.Text.Trim().Contains("P"))
                    {   int pos = range.Text.Trim().IndexOf("P");
                        string str = range.Text.Trim().Replace("P", "O");
                        range.Text = str;} }
                Directory.CreateDirectory((Object)path + "./PUBLI/" + nb);
                Object oSaveAsFile = (Object)path + "./PUBLI/" + nb + "/" + nb + ".doc";
                oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing);
                oWordDoc.Close(ref oFalse, ref  oMissing, ref oMissing);
                oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
            }
    

    unfortunately the process winword.exe don't be kill on the task manager of my server. How i can close the word file correctly?, thank you verry mutch.

    L N G 3 Replies Last reply
    0
    • A abbd

      Hello, I create 4000 files word like this :

      foreach (string s in FUSIONSS_1)
      {

                  String\[\] tbStr2 = s.Split(new Char\[\] { ';' });
                  string nb = tbStr2\[0\];
                  Object oMissing = System.Reflection.Missing.Value;
                  Object oTrue = true;
                  Object oFalse = false;
                  Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
                  Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
                  oWord.Visible = true;
                  oWord.Visible = false;
                  Object oTemplatePath = modelee;
                  oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
                  bool sympb = false; bool E = false; bool n = false; bool p = false; bool r = false;
                 
                  foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
                  {if (range.Text.Trim().Contains("P"))
                      {   int pos = range.Text.Trim().IndexOf("P");
                          string str = range.Text.Trim().Replace("P", "O");
                          range.Text = str;} }
                  Directory.CreateDirectory((Object)path + "./PUBLI/" + nb);
                  Object oSaveAsFile = (Object)path + "./PUBLI/" + nb + "/" + nb + ".doc";
                  oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing,
                  ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                  ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                  ref oMissing, ref oMissing);
                  oWordDoc.Close(ref oFalse, ref  oMissing, ref oMissing);
                  oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
              }
      

      unfortunately the process winword.exe don't be kill on the task manager of my server. How i can close the word file correctly?, thank you verry mutch.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Search results[^] may be unsatisfactory. :)

      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      1 Reply Last reply
      0
      • A abbd

        Hello, I create 4000 files word like this :

        foreach (string s in FUSIONSS_1)
        {

                    String\[\] tbStr2 = s.Split(new Char\[\] { ';' });
                    string nb = tbStr2\[0\];
                    Object oMissing = System.Reflection.Missing.Value;
                    Object oTrue = true;
                    Object oFalse = false;
                    Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
                    Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
                    oWord.Visible = true;
                    oWord.Visible = false;
                    Object oTemplatePath = modelee;
                    oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
                    bool sympb = false; bool E = false; bool n = false; bool p = false; bool r = false;
                   
                    foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
                    {if (range.Text.Trim().Contains("P"))
                        {   int pos = range.Text.Trim().IndexOf("P");
                            string str = range.Text.Trim().Replace("P", "O");
                            range.Text = str;} }
                    Directory.CreateDirectory((Object)path + "./PUBLI/" + nb);
                    Object oSaveAsFile = (Object)path + "./PUBLI/" + nb + "/" + nb + ".doc";
                    oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing,
                    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                    ref oMissing, ref oMissing);
                    oWordDoc.Close(ref oFalse, ref  oMissing, ref oMissing);
                    oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
                }
        

        unfortunately the process winword.exe don't be kill on the task manager of my server. How i can close the word file correctly?, thank you verry mutch.

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #3

        Do you really need to create and dispose of the word application, and the other objects, 4000 times? Don't you think it would be better to do this outside of the loop?


        I know the language. I've read a book. - _Madmatt

        1 Reply Last reply
        0
        • A abbd

          Hello, I create 4000 files word like this :

          foreach (string s in FUSIONSS_1)
          {

                      String\[\] tbStr2 = s.Split(new Char\[\] { ';' });
                      string nb = tbStr2\[0\];
                      Object oMissing = System.Reflection.Missing.Value;
                      Object oTrue = true;
                      Object oFalse = false;
                      Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
                      Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
                      oWord.Visible = true;
                      oWord.Visible = false;
                      Object oTemplatePath = modelee;
                      oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
                      bool sympb = false; bool E = false; bool n = false; bool p = false; bool r = false;
                     
                      foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
                      {if (range.Text.Trim().Contains("P"))
                          {   int pos = range.Text.Trim().IndexOf("P");
                              string str = range.Text.Trim().Replace("P", "O");
                              range.Text = str;} }
                      Directory.CreateDirectory((Object)path + "./PUBLI/" + nb);
                      Object oSaveAsFile = (Object)path + "./PUBLI/" + nb + "/" + nb + ".doc";
                      oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing,
                      ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                      ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                      ref oMissing, ref oMissing);
                      oWordDoc.Close(ref oFalse, ref  oMissing, ref oMissing);
                      oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
                  }
          

          unfortunately the process winword.exe don't be kill on the task manager of my server. How i can close the word file correctly?, thank you verry mutch.

          G Offline
          G Offline
          GenJerDan
          wrote on last edited by
          #4

          Try changing the first oMissing to false.

          abbd wrote:

          oWord.Quit(ref oMissing, ref oMissing, ref oMissing);

          Word may be hanging on a hidden prompt to save changes or suchlike.

          Never give aversion therapy to a masochist. The results are unpredictable. My Mu[sic] My Films My Windows Programs, etc.

          A 1 Reply Last reply
          0
          • G GenJerDan

            Try changing the first oMissing to false.

            abbd wrote:

            oWord.Quit(ref oMissing, ref oMissing, ref oMissing);

            Word may be hanging on a hidden prompt to save changes or suchlike.

            Never give aversion therapy to a masochist. The results are unpredictable. My Mu[sic] My Films My Windows Programs, etc.

            A Offline
            A Offline
            abbd
            wrote on last edited by
            #5

            Unfortunately i have the same problem, please help me.

            G 1 Reply Last reply
            0
            • A abbd

              Unfortunately i have the same problem, please help me.

              G Offline
              G Offline
              GenJerDan
              wrote on last edited by
              #6

              Well, I used to have a similar problem automating Excel in the same way. Best way to troubleshoot it is to NOT run it invisible for the time being. Then you can see what the problem might be.

              Never give aversion therapy to a masochist. The results are unpredictable. My Mu[sic] My Films My Windows Programs, etc.

              A 1 Reply Last reply
              0
              • G GenJerDan

                Well, I used to have a similar problem automating Excel in the same way. Best way to troubleshoot it is to NOT run it invisible for the time being. Then you can see what the problem might be.

                Never give aversion therapy to a masochist. The results are unpredictable. My Mu[sic] My Films My Windows Programs, etc.

                A Offline
                A Offline
                abbd
                wrote on last edited by
                #7

                Hello, How in can run it invisible for the time being? please help me to resolve this great big problem.

                G 1 Reply Last reply
                0
                • A abbd

                  Hello, How in can run it invisible for the time being? please help me to resolve this great big problem.

                  G Offline
                  G Offline
                  GenJerDan
                  wrote on last edited by
                  #8

                  oWord.Visible = true; oWord.Visible = false; Take out that second line. You're running this on a server, right? NOT a good idea according to Microsoft (and my experience). Also check your DCOM settings to be sure permissions are there for remote running. (I don't remember how to do it...Google will help.) Actually, the best advice is to find another way to do it. If you can use Word 2007, while not necessarily easier, it's more likely to work beause you don't actually need Word on the server. (I'll be gone this week, so can't help much. Maybe try Questions & Answers for more.)

                  Never give aversion therapy to a masochist. The results are unpredictable. My Mu[sic] My Films My Windows Programs, etc.

                  modified on Tuesday, May 24, 2011 10:49 AM

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups