PC Review


Reply
Thread Tools Rate Thread

[Automation] Word Activate

 
 
ALESSANDRO Baraldi
Guest
Posts: n/a
 
      2nd Mar 2005
Hi all.
I use the code below to Open Word Application trought Office automation to
to generate my personal TestForm.Doc by a Template(Model.DOT).

All work good, but i don't know why the WordAppl don't stay on Top.

I execute the function on Click Button event's, and at the end of the
function the focus come back to Access and Word go on back.

I don't know absolutly why.

I set to Nothing the two variables [wordApp/wordDoc] on wordDoc_Close()
events.

Have you some solution to give me some idea....?

This is My Code(sorry for Italian comment):

Private WithEvents wordApp As Word.Application
Private WithEvents wordDoc As Word.Document

Private Function BuiltTestForm(strDOT As String, strDOC As String) As
Boolean
Dim ReplSel As Boolean
Dim fld As DAO.Field

On Error GoTo gestErrori

Screen.MousePointer = 11
Set wordApp = GetObject(, "Word.Application")

With wordApp
ReplSel = .Options.ReplaceSelection
.Options.ReplaceSelection = True
Set wordDoc = .Documents.Add(strDOT)
.WindowState = wdWindowStateMaximize
End With
'Loop trought Form Recordset Field's wich have the same Controls Name
'Also BookMark on Model.DOT have the same name, so the code it's easy:
For Each fld In Me.RecordsetClone.Fields
If Me.Controls(fld.Name).Tag <> "EXCLUDE" Then
If Not IsNothing(Me.Controls(fld.Name).Value) Then
If wordDoc.Bookmarks.Exists(fld.Name) Then
wordDoc.Bookmarks(fld.Name).Select
wordApp.Selection.TypeText Text:=Me.Controls(fld.Name).Value
End If
End If
End If
Next
wordDoc.Protect 2, True
wordApp.Options.ReplaceSelection = ReplSel

wordDoc.SaveAs strDOC
wordApp.Visible = True
wordApp.Activate
wordDoc.Activate

BuiltTestForm= True
Esci:
Screen.MousePointer = 0

Exit Function
gestErrori:
If err.Number = 429 Then
'se c'è stato un errore è perchè Word non era già aperto:
'aprilo adesso
Set wordApp = CreateObject("Word.Application")
Resume Next
Else
MsgBox err.Number & "-" & err.Description
GoTo Esci
End If
End Function

Lot of thanks.

--
@Alex (Alessandro Baraldi)
---------------------------------------------------------------------------
http://www.sitocomune.com/
http://www.mantuanet.it/alessandro.baraldi/
---------------------------------------------------------------------------


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Supressing the ctrl-c and other keys during word automation in automation apondu Microsoft VB .NET 1 23rd Jul 2007 10:45 PM
Supressing the ctrl-c and other keys during word automation in automation apondu Microsoft C# .NET 0 19th Jul 2007 10:15 PM
Supressing the ctrl-c and other keys during word automation in automation apondu Microsoft Word Document Management 0 19th Jul 2007 10:15 PM
Supressing the ctrl-c and other keys during word automation in automation apondu Microsoft ASP .NET 0 19th Jul 2007 10:10 PM
Supressing the ctrl-c and other keys during word automation in automation apondu Microsoft Excel Programming 0 19th Jul 2007 10:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:47 PM.