Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automation of Word 1

Status
Not open for further replies.

ninash

Technical User
Jul 6, 2001
163
GB
Hi All,

The code below is a word macro.
My problem is making it run from access or translating it so it is actioned within the code in access.

Is there anyone that can help???

Sub insertdoc()

Selection.WholeStory
Selection.Cut
ActiveDocument.Close

'Here I would also need a command to stop the save prompt happening.

Selection.EndKey Unit:=wdStory
Selection.InsertBreak Type:=wdPageBreak
Selection.Paste

End Sub

Thanks
Tony
 
what is ur code need to do?
If I understand u, I think there is an other way to handle this, but Im not sure what's in ur mind. ;))

In Access there is a general code to switch to word. This code u need for sure.
It's not in my head exactly but search on Word and u get the code on the forum
something like
objWord as object
objDoc as object
set objWord = CreateObject(, "word.application")
set objdoc=objWord.documents or something,
now u can play with what u need....
but let me know ur meanings and I can help u further
Gerard
 
Hi Gerard
I have in my code for setting up Access to open and create a word document
My code creates a document via a template then opens another template and fills that in with data. At this point the code that is shown above is needed.

Firstly it selects all the contents of that document.
Then copies it
Then I need to close this document without getting a save prompt (document is only required for this action No Save Required)
On closing the document you will naturally return to the previous document...
Next it will go to the last line
next insert a page break
lastly paste the copied data into the document

I would like to be able to do this from within access but seeing as the code could be attached to the second template the other option would be to call and run the code within word.
The end result that I am looking for is a clean document without code eg. the document that is being pasted to not the second document that is only a temprary document.

Tony
 
Sub insertdoc()
dim objword as object
dim doc as object
On Error Resume Next
Set objWord = GetObject(, "word.application")
If Err.Number = 429 Then
Set objWord = New Word.Application
End If
On Error GoTo 0

With objWord
.Visible = True
strPath = &quot;<set template, full pathname>&quot;
Set doc = .Documents.Add(strPath)
with doc
.Selection.WholeStory
.Selection.Cut
.ActiveDocument.Close acsavenoprompt

'Here I would also need a command to stop the save prompt happening.

.Selection.EndKey Unit:=wdStory
.Selection.InsertBreak Type:=wdPageBreak
.Selection.Paste

something like this,
play with it, its easy to learn same procedures in word are using in access only set ur references to MS word 10.0

hope this helps,
u can come back when ur tried and not found the solutions
gerard
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top