how to transfer contents of a word file into a text box by clicking a command button.
can anybody help me

Recommended Answers

All 4 Replies

Hi, I think, it is possible when u use MSOffice Type Library. To read word file, you need Microsoft Word (Version No) Object Library.
To add reference
> Project -> Reference -> Microsoft Word (Version No 11 or 12) Object Library

Now Try the coding
Create Word File as C:\Word.doc
This just give idea to read word file. Also this transfers Text Only not images, tables etc.

Private Sub Command1_Click()
   Dim MyDocument       As Document
   Dim RangeText        As Range
   Dim MyApplication    As Application
   
   Set MyApplication = New Application
   Set MyDocument = Documents.Open("C:\Word.doc", Visible:=False)

   Text1.Text = ""
   For Each RangeText In MyDocument.Words
      Text1.Text = Text1.Text & vbCrLf & RangeText.Text
   Next
End Sub

Thanks Ganapathy,
I have used the codes and i am getting error in the following line
----------------------------------------------------------
For Each RangeText In MyDocument.Words
-------------------------------------------------------------
Its a Compile error which is shown and the error is displayed as
error is Method or Datamember not found

Microsoft word 10.0 Object library was found in Reference and included, not 11 or 12
as mentioned by you

Hi, apuamy, I used Microsoft Word 12.0 Object Library. I think you have installed MSOffice 2000. I tried the Google and found something.
I dont know whether it is work or not in Object Library 10.

Private Sub Command1_Click()
   Dim MyDocument       As Document
   Dim RangeText        [B]As Paragraph[/B]
   Dim MyApplication    As Application
   
   Set MyApplication = New Application
   Set MyDocument = Documents.Open("C:\Word.doc", Visible:=False)

   Text1.Text = ""
   For Each RangeText In [B]MyDocument.Paragraphs[/B]
      Text1.Text = Text1.Text & vbCrLf & [B]RangeText.Range.Text[/B]
   Next
End Sub

I referred the page http://msdn.microsoft.com/en-us/library/aa140225(office.10).aspx

Hi ganapathy,
the code is not working. may be i am using word 2002. that is office XP. Any solution in word 2002.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.