By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,098 Members | 939 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,098 IT Pros & Developers. It's quick & easy.

Import text to a variable

P: n/a
Hello all,
I wonder if someone could give me an example of how to assign the text of a
Word document at a given path to a variable ...

x = .......

Any help appreciated ....
Thanks

Ronny
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Ronny Sigo" <ro********@skynet.be> wrote in message news:<40**********************@feed0.news.be.easyn et.net>...
Hello all,
I wonder if someone could give me an example of how to assign the text of a
Word document at a given path to a variable ...

x = .......

Any help appreciated ....
Thanks

Ronny


I bastardized Dev's nice code from here...
http://www.mvps.org/access/modules/mdl0043.htm

And here's the bastardized code...

Option Compare Database

Public Function GetDocFileContents(ByVal strPath As String) As String
'This code was originally written by Dev Ashish
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Dev Ashish
'
Dim mobjWordApp As Word.Application

Set mobjWordApp = New Word.Application
With mobjWordApp
.Visible = False
.Documents.Add strPath
GetDocFileContents = mobjWordApp.ActiveDocument.Content
.Documents.Close False
End With

mobjWordApp.Quit
Set mobjWordApp = Nothing
End Function
Example Call:
Private Sub Command2_Click()
Me.Text0 = GetDocFileContents("C:\Documents and Settings\Pieter
Linden\Desktop\SomeFile.doc")
End Sub
Nov 12 '05 #2

P: n/a
Thanks Pieter :)

"Pieter Linden" <pi********@hotmail.com> schreef in bericht
news:bf**************************@posting.google.c om...
"Ronny Sigo" <ro********@skynet.be> wrote in message

news:<40**********************@feed0.news.be.easyn et.net>...
Hello all,
I wonder if someone could give me an example of how to assign the text of a Word document at a given path to a variable ...

x = .......

Any help appreciated ....
Thanks

Ronny


I bastardized Dev's nice code from here...
http://www.mvps.org/access/modules/mdl0043.htm

And here's the bastardized code...

Option Compare Database

Public Function GetDocFileContents(ByVal strPath As String) As String
'This code was originally written by Dev Ashish
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Dev Ashish
'
Dim mobjWordApp As Word.Application

Set mobjWordApp = New Word.Application
With mobjWordApp
.Visible = False
.Documents.Add strPath
GetDocFileContents = mobjWordApp.ActiveDocument.Content
.Documents.Close False
End With

mobjWordApp.Quit
Set mobjWordApp = Nothing
End Function
Example Call:
Private Sub Command2_Click()
Me.Text0 = GetDocFileContents("C:\Documents and Settings\Pieter
Linden\Desktop\SomeFile.doc")
End Sub

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.