Code to maximise word on opening (Access 2003/Vista (1 Viewer)

M

Mike375

Guest
I am trouble free with with XP but this new Vista Dell is causing me a problem.

The code I use to open Word.docs is

Dim WordObj As Word.Application
Dim WordDoc As Word.Document
Dim WordRange As Word.Range
Set WordObj = CreateObject("Word.Application")
Set WordDoc = WordObj.Documents.Open _
("C:\Letters\0MLCMike.doc")
WordObj.Visible = True

But in Vista only the minimised version opens. For most cases it does not matter as the Word.doc is opened, data from Access inserts to bookmarks, letter prints and Word.doc and Word application is closed.

But I have couple where the Word.doc is opened for editing.

Can anyone help with code that I can add that will open to word doc as maximise.
 
M

Mike375

Guest
Bob,

Yep, tried that one and even maximise in case Australian was needed but go..debug etc

The other bug I have with the Vista is form size. I have about 8 or 9 forms that all open on start up and I use SelectObject to bring theerequired form forward. But now on Vista I am getting slight change in height of a couple of the forms.
 
M

Mike375

Guest
I fixed the form problem, so that is ok

But I can't get a solution on Word only opening as an icon on the task bar.

My main problem area is this code. The Word.dc CommFees is no problem as it is closed. It is CommFeesCopy.doc at the end. The macros are only doing Visible/invisible.

Private Sub Label248_Click()
DoCmd.RunMacro "Macro397", , ""
DoCmd.RunMacro "RSA", , ""

Dim WordObj As Word.Application
Dim WordDoc As Word.Document
Dim WordRange As Word.Range
Set WordObj = CreateObject("Word.Application")
Set WordDoc = WordObj.Documents.Open _
("C:\Letters\CommFees.doc")
WordObj.Visible = True
Set WordRange = WordDoc.GoTo(What:=wdGoToBookmark, Name:="RSA")

WordRange.InsertBefore [Forms]![MasterForm]![OneOffMerge]




WordDoc.Range.Select
WordDoc.ActiveWindow.Selection.Copy

WordDoc.Close False
WordObj.Visible = False

Set WordDoc = WordObj.Documents.Open _
("C:\Letters\CommFeesCopy.doc")
WordObj.Visible = True

WordDoc.Range.Select
WordDoc.ActiveWindow.Selection.Paste

DoCmd.RunMacro "Macro375", , ""
DoCmd.RunMacro "Macro376", , ""
End Sub
 
M

Mike375

Guest
Is the anyone who can solve this?

I have searched high and wide. Maybe the answer is to to have the letters linked in an OLE Object field. They open in full size but I have no idea how to open tehm with code, insert into bookmarks etc.

I have even tried putting WordObj.Maximize in different positions. The results vary from maximising the Access form to a total lock up.
 

LPurvis

AWF VIP
Local time
Today, 23:49
Joined
Jun 16, 2008
Messages
1,269
I wouldn't advocate storing a Word Document in an OLE field in your database purely to get your opened documents to maximise! :-s
(I suppose if it was the only way Vista would obey then you could create a temporary location for such data... but wow - that'd be cumbersome).
Besides - by what automated process are you extracting the document from the OLE field in comparison to the code you're running.

You could try Shelling out the application call (after all - you're creating a new Word instance anyway).

Or you could make an API call to set the window state.
There's no guarantee Vista will acquiesce to that request either (even if it's still supported).

You'd use something like the following in conjunction with FindWindow
http://support.microsoft.com/kb/258511 to get the application's window handle.


Code:
Private Const SW_MINIMIZE = 6
Private Const SW_MAXIMIZE = 3
Private Type POINTAPI
        x As Long
        y As Long
End Type
Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type
Private Type WINDOWPLACEMENT
        Length As Long
        flags As Long
        showCmd As Long
        ptMinPosition As POINTAPI
        ptMaxPosition As POINTAPI
        rcNormalPosition As RECT
End Type
 
Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Private Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long

Public Sub MaximizeWindow(lngHWnd As Long)
    Dim WdwPlc As WINDOWPLACEMENT
    Dim lngRet As Long

    WdwPlc.Length = Len(WdwPlc)
    lngRet = GetWindowPlacement(lngHWnd, WdwPlc)
    WdwPlc.showCmd = SW_MAXIMIZE

    lngRet = SetWindowPlacement(lngHWnd, WdwPlc)
End Sub
 
M

Mike375

Guest
That looks well beyond me:) but thanks for going to the trouble to post up

One I did try was WordObj.WindowState = wdWindowStateMaximize and that that did zero.
 
M

Mike375

Guest
I am part ay there. I made a macro to run a .bat file to open the same letter

DoCmd.RunMacro "Macro2", , ""

Dim WordObj As Word.Application
Dim WordDoc As Word.Document
Dim WordRange As Word.Range
Set WordObj = CreateObject("Word.Application")
Set WordDoc = WordObj.Documents.Open _
("C:\Letters\0Letter1Mike.doc")
WordObj.Visible = True

Set WordRange = WordDoc.GoTo(What:=wdGoToBookmark, Name:="a7")

WordDoc.Bookmarks("a7").Select

The macro/bat opend full size and that seems to force the code that opens the letter to to do the same.

I have a macro on the letter which closes and saves and closes Word. That is just

Sub Macro1()
Application.Quit True
End Sub

But I am left with the Word itself open. This is now my onl bug. Is there something I can use that will close any and all Word applications.
 
M

Mike375

Guest
George, 2003 on Vista. Howver I got it fixed

I managed to get it fixed. Only took all day:D

Add this maro which runs a little .bat file DoCmd.RunMacro "Macro2", , "" which opens the doc.
Dim WordObj As Word.Application
Dim WordDoc As Word.Document
Dim WordRange As Word.Range
Set WordObj = CreateObject("Word.Application")
Set WordDoc = WordObj.Documents.Open _
("C:\Letters\0Letter1Mike.doc")
I removed WordObj.Visible = True
Set WordRange = WordDoc.GoTo(What:=wdGoToBookmark, Name:="a7")

WordDoc.Bookmarks("a7").Select

Actually just a macro/bat would open the document in maximised but you need the other stuff for Bookmarks etc. Actually for most of our pre set letters it does matter as they open, Access sticks in the details including LettetHead, copies the document writing, prints it, closes and a new record for the person is opened in Access in a Memo filed and the contents of the letter pastes in.

Macro and bat file to the rescue:D

And George, all that is in the bat file us \Letters\0Letter1Mike.doc
 

LPurvis

AWF VIP
Local time
Today, 23:49
Joined
Jun 16, 2008
Messages
1,269
Can I just confirm - is all this still all about getting the newly opened Word instance Document to receive the focus and be maximised?

>> "See super-Bob's (the guy with the new logo in his siggy)"
LOL - Wow Bob. You didn't waste any time! How did you get the agreement back from the logo licencing people so quickly? Did you bribe them? ;-)
 
M

Mike375

Guest
Can I just confirm - is all this still all about getting the newly opened Word instance Document to receive the focus and be maximised?

>> "See super-Bob's (the guy with the new logo in his siggy)"
LOL - Wow Bob. You didn't waste any time! How did you get the agreement back from the logo licencing people so quickly? Did you bribe them? ;-)

Yes. The letters open are edited or written and then closed/saved. Then "print" fills in the bookmarks, inlcuding our letterhead, the contents is copied and pasted back to a new record in the persons Many table and the word doc closes without saving.

To be perfectly honest we could have lived with having to click the minimised icon but you know how it can be:D, especially when the stuff if so smooth on XP.

My only bug at the moment is that I made a macro for the word.docs (Application.Quit True) but it need two clicks because the DOS screen from the bat file is still open. Maybe there is some way to have the counterpart of RunMacro in Word so one click would close the lot.
 
M

Mike375

Guest
PS,

All the word.docs are existing, no blank page starts as they have bookmarks inlcuding in the footer.
 

StueyR

New member
Local time
Today, 23:49
Joined
May 22, 2012
Messages
1
Well, it might be a little late for you, but if anyone else reads this (as I did) searching for a solution to the same issue it appears to be to change the "verb" in the form properties that hold the OLE field to -2.

I discovered this by accident as I had two forms which I thought were identical but which behaved differently. I noticed this difference, changed the other, and hey presto.

Don't ask me why it works, but work it does! :D
 

JohnWick

New member
Local time
Today, 15:49
Joined
Jun 3, 2018
Messages
1
Hi,

This is what worked for me:

WordDoc.Application.Activate
 

Users who are viewing this thread

Top Bottom