To word

A

alvin Kuiper

Hi
I have
Dim wdApp As Word.Application
Set wdApp = New Word.Application
With wdApp
.Documents.Open FileName:="c:\test.doc"
With .Selection
.EndKey Unit:=wdStory
.TypeParagraph
.TypeText filnavn.Value
End With
.ActiveDocument.Save
.Quit
End With
Set wdApp = Nothing

I get a error in
.EndKey Unit:=wdStory
I know that this line should make me go to the end of the document?

Hope some one can help

Alvin
 
A

Alex Dybenko

Hmm, very strange error. Do you have a reference to word in your project?
if you write:
wdApp.Selection.EndKey Unit:=wdStory

at me this like works fine.
 
A

alvin Kuiper

Hi Alex
Its stop the same place at:
wdApp.Selection.EndKey Unit:=wdStory


And mark "wdStory" with error
"Can't find object or library"

regards
Alvin
 
A

Alex Dybenko

Hi,
it looks like you don't have a reference to word library, in this case you
have to declare necessary word constants in your application:

const wdStory=6

or just replace with actual values:

wdApp.Selection.EndKey Unit:=6
 
D

Douglas J. Steele

Oops: That got sent too soon.

Wouldn't there be issues with the lines

Dim wdApp As Word.Application
Set wdApp = New Word.Application

if there wasn't a reference to the Word library?

I don't know the Word model all that well: is wdStory available in all
versions?
 
J

John Nurick

Good thought. I wonder if this could be one of the situations where
Selection doesn't work unless the document window is visible. If so, the
problem will be solved by using a Range instead (which is almost always
preferable when automating Word anyway).

Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim raR As Word.Range

Set wdApp = New Word.Application
With wdApp
Set wdDoc = .Documents.Open FileName:="c:\test.doc"
Set raR = wdDoc.Bookmarks("\EndOfDoc").Range
With .raR
.InsertParagraph
.Collapse wdCollapseEnd
.InsertAfter filnavn.Value
End With
wdDoc.Close True
.Quit
End With
Set wdApp = Nothing
 
A

alvin Kuiper

Hi John
get an error allready in VBA this line turns red:

Set wdDoc = .Documents.Open FileName:="c:\test.doc"

regards
Alvin
 
A

Alex Dybenko

Hi Doug,
yes, this I saw, but still constant was not evaluated, even it should, this
is quite strange....

Alex
 
A

alvin Kuiper

Hi
and thanks all
but now i get an error in:
With .raR
stop at .raR
error " method or data member not found" ???

regards
alvin


"John Nurick" skrev:
 
J

John Nurick

Drop the dot:

With raR

Hi
and thanks all
but now i get an error in:
With .raR
stop at .raR
error " method or data member not found" ???

regards
alvin


"John Nurick" skrev:
 
A

alvin Kuiper

Hi John
and thanks to all
I change the script a little bit to:
Private Sub tilword_Click()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim raR As Word.Range
Set wdApp = New Word.Application
With wdApp
Set wdDoc = .Documents.Open(FileName:="c:\test.doc")

Set raR = wdDoc.Bookmarks("\EndOfDoc").Range

raR.InsertParagraph
raR.Collapse
raR.InsertAfter filnavn.Value
End With
wdDoc.Close True
Set wdApp = Nothing
End Sub

This works fine
regards
alvin


"John Nurick" skrev:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top