Text file to Word document using VB6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ravitunk
    New Member
    • Jun 2007
    • 88

    Text file to Word document using VB6

    hi all....can anyone tell me how to convert a textfile to word document using VB6....plz reply ASAP...i will be thankful...
  • vdraceil
    New Member
    • Jul 2007
    • 236

    #2
    just change the extenstion,it'l l become a word document..
    make sure to add Microsoft Scripting Runtime to ur project references,then add the following code..

    Code:
    dim fso as filesystemobject
    
    private sub form_load()
     fso.copyfile("filepath\filename.txt","filepath\filename.doc")
     msgbox "saved successfully."
    end sub

    Comment

    • ravitunk
      New Member
      • Jun 2007
      • 88

      #3
      thanks a lot for ur reply....but my Visual Basic has a problem....ever ytime I click on the Project menu it says 'Visual Basic has encountered a problem and needs to close'......... .can u please give me another way to add 'Microsoft Scripting Runtime' to my project.......o nce again thanks for ur reply...

      Originally posted by vdraceil
      just change the extenstion,it'l l become a word document..
      make sure to add Microsoft Scripting Runtime to ur project references,then add the following code..

      Code:
      dim fso as filesystemobject
      
      private sub form_load()
       fso.copyfile("filepath\filename.txt","filepath\filename.doc")
       msgbox "saved successfully."
      end sub

      Comment

      • ravitunk
        New Member
        • Jun 2007
        • 88

        #4
        hi...i wrote the following function...
        Code:(text)
        1.Private Function Convert2word(tx tSourceFile As String) As String
        2.Dim fso As FileSystemObjec t
        3.fso.CopyFile txtSourceFile, "D:\filename.do c"
        4.Convert2word = "D:\filename.do c"
        5.End Function

        But its hitting an error saying...Runtim e error '91' Object variable or with block variable not set....at the line 3 in the above code....what does it mean and can anyone help me out plz???...

        Originally posted by vdraceil
        just change the extenstion,it'l l become a word document..
        make sure to add Microsoft Scripting Runtime to ur project references,then add the following code..

        Code:
        dim fso as filesystemobject
        
        private sub form_load()
         fso.copyfile("filepath\filename.txt","filepath\filename.doc")
         msgbox "saved successfully."
        end sub

        Comment

        • vdraceil
          New Member
          • Jul 2007
          • 236

          #5
          Originally posted by ravitunk
          hi...i wrote the following function...
          Code:(text)
          1.Private Function Convert2word(tx tSourceFile As String) As String
          2.Dim fso As FileSystemObjec t
          3.fso.CopyFile txtSourceFile, "D:\filename.do c"
          4.Convert2word = "D:\filename.do c"
          5.End Function

          But its hitting an error saying...Runtim e error '91' Object variable or with block variable not set....at the line 3 in the above code....what does it mean and can anyone help me out plz???...
          Hi ravitunk,well that must be a problem of copyfile method of the filesystemobjec t..i too get an error for the same..i'll find out why and reply u back.

          why dont u try this(if u can add Microsoft Scripting Runtime to ur project references)..

          Code:
          Dim fso as filesystemobject
          dim f as file
          
          Private Sub Form_Load()
           Set f = fso.getfile("path\filename.txt")
            f.copy ("path\filename.doc")
          End Sub
          try this(if u cant add that reference to ur project)..

          Code:
          Dim fso as object
          Dim f as object
          
          Private Sub Form_Load()
           set fso = createobject("Scripting.FileSystemObject")
           set f = fso.getfile("path\filename.txt")
           f.copy ("path\filename.doc")
          End Sub

          Comment

          • ravitunk
            New Member
            • Jun 2007
            • 88

            #6
            thks a lot for ur reply....i tried the following code....and it worked....but when I goto the Word document and try to open it....it gives a prompt saying..."Micro soft Word can't import the specified format. This feature is currently not installed.Would you like to install it now?"......with Yes and No buttons.....wha ts this....if I click No then its opening the document with the contents.....pl ease tel me more abt that prompt...

            Code:
            Dim fso as object
            Dim f as object
            Private Sub Form_Load()
             set fso = createobject("Scripting.FileSystemObject")
             set f = fso.getfile("path\filename.txt")
             f.copy ("path\filename.doc")
            End Sub


            Originally posted by vdraceil
            Hi ravitunk,well that must be a problem of copyfile method of the filesystemobjec t..i too get an error for the same..i'll find out why and reply u back.

            why dont u try this(if u can add Microsoft Scripting Runtime to ur project references)..

            Code:
            Dim fso as filesystemobject
            dim f as file
            
            Private Sub Form_Load()
             Set f = fso.getfile("path\filename.txt")
              f.copy ("path\filename.doc")
            End Sub
            try this(if u cant add that reference to ur project)..

            Code:
            Dim fso as object
            Dim f as object
            
            Private Sub Form_Load()
             set fso = createobject("Scripting.FileSystemObject")
             set f = fso.getfile("path\filename.txt")
             f.copy ("path\filename.doc")
            End Sub

            Comment

            • vdraceil
              New Member
              • Jul 2007
              • 236

              #7
              Originally posted by ravitunk
              thks a lot for ur reply....i tried the following code....and it worked....but when I goto the Word document and try to open it....it gives a prompt saying..."Micro soft Word can't import the specified format. This feature is currently not installed.Would you like to install it now?"......with Yes and No buttons.....wha ts this....if I click No then its opening the document with the contents.....pl ease tel me more abt that prompt...

              Code:
              Dim fso as object
              Dim f as object
              Private Sub Form_Load()
               set fso = createobject("Scripting.FileSystemObject")
               set f = fso.getfile("path\filename.txt")
               f.copy ("path\filename.doc")
              End Sub
              I dont have such problem with the codehere ravitunk.eveyth ing is perfect here(I have MS Office 2007)..i dont know what the problem might be-will reply you once i find out..

              Comment

              • ravitunk
                New Member
                • Jun 2007
                • 88

                #8
                ohh ok...thks for ur replies and help.....actual ly my task is to copy the textfile content to an exiting pdf file which has a header and a footer....plz revert back if u know this.....or

                to accomplish the same task am planning to convert the txtfile to a template word document(which has header and footer)...and then want to convert tht to pdf file....
                .............an yone of the above two approaches will be fine......plz reply back soon.....thks for ur help once again....


                Originally posted by vdraceil
                I dont have such problem with the codehere ravitunk.eveyth ing is perfect here(I have MS Office 2007)..i dont know what the problem might be-will reply you once i find out..

                Comment

                Working...