Home

Macros and Programming

 

CardboxForumsMacros and Programming > "Opening Word using a Macro in Cardbox"

Opening Word using a Macro in Cardbox

Current user: [none]
Register / Log In · Help

Posted By Post

SHopkin

19-May-2006 13:32

Since upgrading to version 3 we have had our macro re-written for opening a document in MS Word. Unfortunately we each use this macro 100 + times a day and it opens Word each time rather than just opening a Word document. Our technical person has tried & tried but without joy. Can anyone advise ?

filen="H:\documents\cv\"& fields("CV")&".doc"
' The following 2 lines are commented out as they create new instances of the word application
 set word=createobject("Word.Application")
 word.documents.open(filen)

' The following 4 lines open the CV file using an existing copy of Word
' On Error Resume Next
' set word=getobject(,"Word.Document")
' If IsObject(Word) = False Then Set Word = CreateObject("word.application")
' word.documents.open(filen)

word.application.visible = true

Paul Irvine

19-May-2006 15:52

Try changing the GetObject line to

set word=Getobject(,"Word.Application")

You will probably have to use Windows SetWindowPos API to bring Word to the front. There is some useful information at http://www.codeproject.com/cs/miscctrl/winwordcontrol.asp?print=true about this.

Alex Maines

20-May-2006 08:36

The best approach is to use a little of both the solutions provided.

' First, try to find an existing copy of MSWord:
Dim wpApp
Set wdApp = GetObject(, "Word.Application")

' If there isn't one, make one
If wdApp = Nothing then Set wdApp = CreateObject("Word.Application")

' Bring Word to the front - No need to call any Windows API functions
wdApp.Visible = true
wdApp.Activate

Charles Welling

22-May-2006 07:49

Why don't you make the field clickable? From your macro I gather that all CV's are in H:\documents\cv\. Just give the field the caption "file://H:\documents\cv\".
You would have to add the ".doc" suffx to your filenames though, but batch edit would solve that in just a few seconds.
After you've done this, the filename becomes clickable and the document will open always in the same instance of Word. No macro needed.

This feature was added in build 4217.

Charles

Martin Collis

7-Dec-2007 16:35

Charles, tried your method which was also recommended by someone else. Looks like a perfect solution for us to open associated WORD documents that have their address completely specified within our cardbox record.
However, after adding the caption FILE://, clicking on the field seems to do nothing other than highlight it!
Have I missed something here?
(We are using CB3 recently purchased)

Charles Welling

10-Dec-2007 08:59

Martin, make sure that the database is opened in the "completely trusted" mode. Below the list of filenames that appears when you select File, Open is a box that specifies the safety level. Any level lower than completely trusted does not allow the opening of external files from a record.
You can set the default safety level for your server using the "Server safety" button on the same screen.

Quick Reply

Please log in or register before trying to post a reply.

 
© 2010 Cardbox Software Limited   Home