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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Outlook/Word 1

Status
Not open for further replies.

PerlIsGood

Programmer
Jan 24, 2002
154
US
This post continued from the following VBScript forum. I just thought someone over here might be able to help:

thread329-200792 The following code is written within a custom Outlook form. Everything works, I just need some fine-tuning.

Code:
FileLoc = Server & FormFiles & "formschedule.doc"
    On Error Resume Next
    Set oWord = GetObject(, "Word.Application")
    If Err.Number <> 0 Then
        Err.Clear
        Set oWord = CreateObject(&quot;Word.Application&quot;)
    End If
    
    oWord.Documents.Open (FileLoc)
        oWord.ActiveDocument.Bookmarks(&quot;var1&quot;).Select
        oWord.Selection.InsertBefore (var1)
  oWord.Visible = True
  Set oWord = Nothing

I only have two problems with this:
1. The code opens the doc successfully, but does not pull the window up and make it the focus (unless Word was not open). How do I set the focus/make this window the active window?

2. Has anyone ever worked with Word form fields before? I can only seem to insert text before/after the bookmark. Does anyone know of a way to replace/insert text inside the form field?
 
1) oWord.ActiveDocument.Activate

2) A bookmark is not a Form field. If it's a textinput object, as it appears to be, use

oWord.ActiveDocument.FormFields(&quot;var1&quot;).Result = &quot;Hi&quot;
Jon Hawkins
 
Fooey! I hadn't tested this completely before replying. The section for FormFields works perfectly! The other part, ActiveDoc...Activate, isn't working. When word is already open, it will still stay minimized or behind other windows.

Any other options...?

I've tried (and failed):
oWord.Maximize
oWord.ActiveDocument.Maximize
oWord.ActiveDocument.Display
oWord.Display

I don't even know if these are valid methods/properties, but I've been unable to find the App and Document listings in the ObjBrowser.
 
The Activate method will make the application the active application, illustrated by the inset panel on the Windows taskbar.

To maximize/minimize/restore the application window, use the WindowState property.

oWord.Windowstate = 1 'maximize Jon Hawkins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top