473,394 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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...
Aug 4 '08 #1
7 2677
vdraceil
236 100+
just change the extenstion,it'll become a word document..
make sure to add Microsoft Scripting Runtime to ur project references,then add the following code..

Expand|Select|Wrap|Line Numbers
  1. dim fso as filesystemobject
  2.  
  3. private sub form_load()
  4.  fso.copyfile("filepath\filename.txt","filepath\filename.doc")
  5.  msgbox "saved successfully."
  6. end sub
Aug 4 '08 #2
thanks a lot for ur reply....but my Visual Basic has a problem....everytime 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.......once again thanks for ur reply...

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

Expand|Select|Wrap|Line Numbers
  1. dim fso as filesystemobject
  2.  
  3. private sub form_load()
  4.  fso.copyfile("filepath\filename.txt","filepath\filename.doc")
  5.  msgbox "saved successfully."
  6. end sub
Aug 4 '08 #3
hi...i wrote the following function...
Code:(text)
1.Private Function Convert2word(txtSourceFile As String) As String
2.Dim fso As FileSystemObject
3.fso.CopyFile txtSourceFile, "D:\filename.doc"
4.Convert2word = "D:\filename.doc"
5.End Function

But its hitting an error saying...Runtime 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???...

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

Expand|Select|Wrap|Line Numbers
  1. dim fso as filesystemobject
  2.  
  3. private sub form_load()
  4.  fso.copyfile("filepath\filename.txt","filepath\filename.doc")
  5.  msgbox "saved successfully."
  6. end sub
Aug 12 '08 #4
vdraceil
236 100+
hi...i wrote the following function...
Code:(text)
1.Private Function Convert2word(txtSourceFile As String) As String
2.Dim fso As FileSystemObject
3.fso.CopyFile txtSourceFile, "D:\filename.doc"
4.Convert2word = "D:\filename.doc"
5.End Function

But its hitting an error saying...Runtime 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 filesystemobject..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)..

Expand|Select|Wrap|Line Numbers
  1. Dim fso as filesystemobject
  2. dim f as file
  3.  
  4. Private Sub Form_Load()
  5.  Set f = fso.getfile("path\filename.txt")
  6.   f.copy ("path\filename.doc")
  7. End Sub
try this(if u cant add that reference to ur project)..

Expand|Select|Wrap|Line Numbers
  1. Dim fso as object
  2. Dim f as object
  3.  
  4. Private Sub Form_Load()
  5.  set fso = createobject("Scripting.FileSystemObject")
  6.  set f = fso.getfile("path\filename.txt")
  7.  f.copy ("path\filename.doc")
  8. End Sub
Aug 13 '08 #5
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..."Microsoft 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.....whats this....if I click No then its opening the document with the contents.....please tel me more abt that prompt...

Expand|Select|Wrap|Line Numbers
  1. Dim fso as object
  2. Dim f as object
  3. Private Sub Form_Load()
  4.  set fso = createobject("Scripting.FileSystemObject")
  5.  set f = fso.getfile("path\filename.txt")
  6.  f.copy ("path\filename.doc")
  7. End Sub


Hi ravitunk,well that must be a problem of copyfile method of the filesystemobject..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)..

Expand|Select|Wrap|Line Numbers
  1. Dim fso as filesystemobject
  2. dim f as file
  3.  
  4. Private Sub Form_Load()
  5.  Set f = fso.getfile("path\filename.txt")
  6.   f.copy ("path\filename.doc")
  7. End Sub
try this(if u cant add that reference to ur project)..

Expand|Select|Wrap|Line Numbers
  1. Dim fso as object
  2. Dim f as object
  3.  
  4. Private Sub Form_Load()
  5.  set fso = createobject("Scripting.FileSystemObject")
  6.  set f = fso.getfile("path\filename.txt")
  7.  f.copy ("path\filename.doc")
  8. End Sub
Aug 13 '08 #6
vdraceil
236 100+
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..."Microsoft 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.....whats this....if I click No then its opening the document with the contents.....please tel me more abt that prompt...

Expand|Select|Wrap|Line Numbers
  1. Dim fso as object
  2. Dim f as object
  3. Private Sub Form_Load()
  4.  set fso = createobject("Scripting.FileSystemObject")
  5.  set f = fso.getfile("path\filename.txt")
  6.  f.copy ("path\filename.doc")
  7. End Sub
I dont have such problem with the codehere ravitunk.eveything is perfect here(I have MS Office 2007)..i dont know what the problem might be-will reply you once i find out..
Aug 13 '08 #7
ohh ok...thks for ur replies and help.....actually 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....
.............anyone of the above two approaches will be fine......plz reply back soon.....thks for ur help once again....


I dont have such problem with the codehere ravitunk.eveything is perfect here(I have MS Office 2007)..i dont know what the problem might be-will reply you once i find out..
Aug 13 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: mickeydisn | last post by:
Sub: C++ Word automation Extract text hello. I want extact text form a word document using a visual c++ programme. I have see a lot of documentation. and my analysis is that I must use a...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
1
by: adam lital | last post by:
Hi, I have word document and i want to replace a specific text with a bookmark using code. Example: in the document i have the text and i want to replace this to a bookmark called ClientName....
31
by: microsoft.news.com | last post by:
I need to read a text file but I need to start on line 2 of the file, How can I start reading the text file starting with the second line and not the first line in the file?
2
by: Claus - Arcolutions | last post by:
I got a word document as a stream, and I want to get the text from the word document. But I cant seem to find anything to use for that purpose. The "Microsoft office ?.object" com reference, only...
2
by: Kevin K | last post by:
Hi, I'm having a problem with extracting text from a Word document using StreamReader. As I'm developing a web application, I do NOT want the server to make calls to Word. I want to simply...
5
by: Carstonio | last post by:
I use ASP to display links to Word documents on an intranet. Is there a way in ASP to do text searches on the documents' contents? I want the results to have the link to the Word document plus two...
1
by: Darsin | last post by:
What i am doing is to pull the data from a CMS and import it to Word 2007 Beta and i also have to export the data from Word 2007 Beta back to that CMS. We have with us two Web Services of the CMS....
16
by: Neil | last post by:
I posted a few days ago that it seems to me that the Access 2007 rich text feature does not support: a) full text justification; b) programmatic manipulation. I was hoping that someone might...
0
by: satarupa | last post by:
I want to read the formatted (bold,underline,italics) text of a word dcoument using c# i can read the document even the paragraphn in it but not the formatted text plzz help following is the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.