Working with files in VB 6.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krish1315
    New Member
    • Jan 2007
    • 6

    #16
    Why Reading a word document in MS Word 2003 is slow as compared to reading MS Word 2000

    Comment

    • amitp
      New Member
      • Dec 2006
      • 49

      #17
      I've to append some MS Word 2003 documents to a single document. My word documents contain tables. Each document contains a single table. My code appended the files but there remains some spaces between the tables. Why these spaces comes. I want that the next word document should start at the EOF of immidiate above. I don't know much 'bout WORD 2003 . Could any one suggest me to handle the issue. I'm providing the code.

      Dim wrdApp As Word.Applicatio n
      Dim wrdDoc As New Word.Document
      Dim file1, file2, file3, docName As String
      file1 = "C:\Test.rt f"
      file2 = "C:\Q0000001.rt f"
      file3 = "C:\Q0000002.rt f"

      Set wrdApp = CreateObject("W ord.Application ")
      wrdApp.Visible = False
      Set wrdDoc = wrdApp.Document s.Add(file1)
      wrdDoc.Applicat ion.Selection.I nsertFile (file2)
      wrdDoc.Applicat ion.Selection.I nsertBreak (WdBreakType.wd LineBreak)
      wrdDoc.Applicat ion.Selection.I nsertFile (file3)
      wrdDoc.Applicat ion.Selection.I nsertBreak (WdBreakType.wd LineBreak)
      wrdDoc.SaveAs (file1)
      wrdDoc.Close

      Comment

      • amitp
        New Member
        • Dec 2006
        • 49

        #18
        In addition to my previous query i've one more query. I want to read a Word document which contains some field values. How can i get the field values one by one by reading the document. Below is the content of my word document.
        I want to use the word object. Waiting 4 ur reply.


        <<klntgeg>> <<lynapinf>> <<apparatuur> > <<infra>> <<totaal>> <<btwdisc>> <<discove>> <<sinfra>> <<CNTKLANT>> <<gidsv>> <<install>> <<betaling>> <<ondertek>>

        Comment

        • diSangro
          New Member
          • Jan 2007
          • 69

          #19
          Goete Morgen....Amitp !

          try to open your rtf as text file , if you do so a field code is identified by a keyword like MACROBUTTON (Note : length =11 ) etc, followed by the field name (like <<totaal>> )

          If you create your rtf having field codes in c:\New\Input.rt f then you can try this vb code:
          '---------------------------------------------------------------------------------------------------------------
          Private Sub CommandButton2_ Click()
          Const ForReading = 1
          Dim fs, f, count, cend, myLine ' string count/end,line buffer for file reading
          Set fs = CreateObject("S cripting.FileSy stemObject")
          Set f = fs.OpenTextFile ("\New\Input.rt f", ForReading, TristateFalse)
          Dim Sfind 'string to find
          Sfind = "<<"
          Do
          myLine = f.Readline
          count = InStr(1, myLine, Sfind, 1)
          While count <> 0
          cend = InStr(count, myLine, ">>", 1) + 2
          MsgBox Mid(myLine, count, cend - count)
          count = InStr(count + Len(Sfind), myLine, Sfind, 1)
          Wend
          Loop Until Len(myLine) < 11 ' buffer too small ends the loop
          End Sub

          '-------------------------------------------------------------------------------------------

          It will show all the field names in a Msg Box....Exit is when myLine length is < than 11 (less than MACROBUTTON)... ..Does it help?


          Bye !





          Originally posted by amitp
          In addition to my previous query i've one more query. I want to read a Word document which contains some field values. How can i get the field values one by one by reading the document. Below is the content of my word document.
          I want to use the word object. Waiting 4 ur reply.


          <<klntgeg>> <<lynapinf>> <<apparatuur> > <<infra>> <<totaal>> <<btwdisc>> <<discove>> <<sinfra>> <<CNTKLANT>> <<gidsv>> <<install>> <<betaling>> <<ondertek>>

          Comment

          • amitp
            New Member
            • Dec 2006
            • 49

            #20
            thanks for the ans. but could u help me in this query.

            I've to append some MS Word 2003 documents to a single document. My word documents contain tables. Each document contains a single table. My code appended the files but there remains some spaces between the tables. Why these spaces comes. I want that the next word document should start at the EOF of immidiate above. I don't know much 'bout WORD 2003 . Could any one suggest me to handle the issue. I'm providing the code.

            Dim wrdApp As Word.Applicatio n
            Dim wrdDoc As New Word.Document
            Dim file1, file2, file3, docName As String
            file1 = "C:\Test.rt f"
            file2 = "C:\Q0000001.rt f"
            file3 = "C:\Q0000002.rt f"

            Set wrdApp = CreateObject("W ord.Application ")
            wrdApp.Visible = False
            Set wrdDoc = wrdApp.Document s.Add(file1)
            wrdDoc.Applicat ion.Selection.I nsertFile (file2)
            wrdDoc.Applicat ion.Selection.I nsertFile (file3)
            wrdDoc.SaveAs (file1)
            wrdDoc.Close

            Comment

            • diSangro
              New Member
              • Jan 2007
              • 69

              #21
              As far as you terminate one table a newline char is added ,
              that's why you have this problem...can be done but now I'm goin to have lunch!
              Bye !

              Originally posted by amitp
              thanks for the ans. but could u help me in this query.

              I've to append some MS Word 2003 documents to a single document. My word documents contain tables. Each document contains a single table. My code appended the files but there remains some spaces between the tables. Why these spaces comes. I want that the next word document should start at the EOF of immidiate above. I don't know much 'bout WORD 2003 . Could any one suggest me to handle the issue. I'm providing the code.

              Dim wrdApp As Word.Applicatio n
              Dim wrdDoc As New Word.Document
              Dim file1, file2, file3, docName As String
              file1 = "C:\Test.rt f"
              file2 = "C:\Q0000001.rt f"
              file3 = "C:\Q0000002.rt f"

              Set wrdApp = CreateObject("W ord.Application ")
              wrdApp.Visible = False
              Set wrdDoc = wrdApp.Document s.Add(file1)
              wrdDoc.Applicat ion.Selection.I nsertFile (file2)
              wrdDoc.Applicat ion.Selection.I nsertFile (file3)
              wrdDoc.SaveAs (file1)
              wrdDoc.Close

              Comment

              • amitp
                New Member
                • Dec 2006
                • 49

                #22
                Do u hav a solution for the one, then plz send it. Thanking You

                Comment

                • diSangro
                  New Member
                  • Jan 2007
                  • 69

                  #23
                  ...the easiest way would be to open your rtf file in Word , place the cursor at the right end of the table and pres Del ... the new line will be removed and the table will be merged with the second creating the whole table.

                  Of course if you have ...let's say a hundred tables to merge this is not really practical I know , in this case you need a specific prog which removes newlines.
                  Is this the case?

                  Originally posted by amitp
                  Do u hav a solution for the one, then plz send it. Thanking You

                  Comment

                  • Killer42
                    Recognized Expert Expert
                    • Oct 2006
                    • 8429

                    #24
                    Originally posted by diSangro
                    ...the easiest way would be to open your rtf file in Word , place the cursor at the right end of the table and pres Del ... the new line will be removed and the table will be merged with the second creating the whole table.

                    Of course if you have ...let's say a hundred tables to merge this is not really practical I know , in this case you need a specific prog which removes newlines.
                    Is this the case?
                    Surely you could do that in the code which is already being used to load them.

                    Comment

                    • amitp
                      New Member
                      • Dec 2006
                      • 49

                      #25
                      How can i read a doc file line by line there by calculating the total number of lines and identify the blank lines and then deleting the balnk lines from the file. can anybody having any code for this using VB 6.0

                      Comment

                      • amitp
                        New Member
                        • Dec 2006
                        • 49

                        #26
                        1> How can i read a doc file line by line there by calculating the total number of lines and identify the blank lines and then deleting the balnk lines from the file. can anybody having any code for this using VB 6.0

                        2> to replace the field values with text i've used the following code and that works fine for only for texts of max length of 255 characters and beyond that is gives an error Error- 5854 : String Parameter too long. Can any one hav the solution for this.

                        With wrdRepApp.Selec tion.find
                        .Text = sFind
                        .Replacement.Te xt = sReplace
                        .Forward = True
                        .Wrap = wdFindContinue
                        .Format = False
                        .MatchCase = False
                        .MatchWholeWord = False
                        .MatchKashida = False
                        .MatchDiacritic s = False
                        .MatchAlefHamza = False
                        .MatchControl = False
                        .MatchWildcards = False
                        .MatchSoundsLik e = False
                        .MatchAllWordFo rms = False

                        End With

                        Comment

                        • Killer42
                          Recognized Expert Expert
                          • Oct 2006
                          • 8429

                          #27
                          Originally posted by amitp
                          Code:
                          ...
                          Set wrdDoc = wrdApp.Documents.Add(file1)
                          wrdDoc.Application.Selection.InsertFile (file2)
                          [B]wrdDoc.Application.Selection.InsertBreak (WdBreakType.wdLineBreak)[/B]
                          wrdDoc.Application.Selection.InsertFile (file3)
                          [B]wrdDoc.Application.Selection.InsertBreak (WdBreakType.wdLineBreak)[/B]
                          You are asking how to avoid the blank lines between inserted documents. But surely your code (see highlighted lines above) is explicitly inserting a blank line after each file?

                          Comment

                          • Killer42
                            Recognized Expert Expert
                            • Oct 2006
                            • 8429

                            #28
                            Originally posted by amitp
                            2> to replace the field values with text i've used the following code and that works fine for only for texts of max length of 255 characters and beyond that is gives an error Error- 5854 : String Parameter too long. Can any one hav the solution for this.
                            One way to get around this sort of thing is to replace sections of the text. As a small example to illustrate the concept, let's say you want to convert the string "AAAAAAAA" to "ABCDABCD". You can do the same by converting all "AAAA" to "ABCD". You can also convert all "AAAA" to "@" then convert all "@" to "ABCD". Or convert all "AA" to "@", then convert all "@@" to "ABCD".

                            You can expand on this sort of technique - just use your imagination.

                            Comment

                            • amitp
                              New Member
                              • Dec 2006
                              • 49

                              #29
                              i deleted the highlighted lines but the spaces still remains. i happens with the case if the RTF file consists of only a table. That means when the files consisting of tables only appended explicitly a blank line is added. This is not the case with text. So kindly look into this.

                              Comment

                              • Killer42
                                Recognized Expert Expert
                                • Oct 2006
                                • 8429

                                #30
                                Originally posted by amitp
                                i deleted the highlighted lines but the spaces still remains. i happens with the case if the RTF file consists of only a table. That means when the files consisting of tables only appended explicitly a blank line is added. This is not the case with text. So kindly look into this.
                                Can you try playing around with commands like this between inserts?
                                Code:
                                wrdDoc.Application.Selection.TypeBackspace
                                  [B]and/or[/B]
                                wrdDoc.Application.Selection.MoveLeft Unit:=wdCharacter, Count:=1

                                Comment

                                Working...