Avatar billede toh Nybegynder
03. juni 2004 - 19:44 Der er 16 kommentarer og
2 løsninger

Hvordan får jeg den til at se om word er åben før den åbnes

Jeg kunne godt tænke mig at programmet kan se om "Word" er åben inden den åbner "Word" på ny. Hvis "Word" er åben skal den blot indlæse den aktuelle skabelon som en fil, hvordan programmere jeg mig ud af det.

Private Sub cmdOK_Click()
    SetFocus
    Set ObjW = CreateObject("word.application")
    With ObjW
        Select Case True
            Case Option1.Value
                .Visible = True
                .Documents.Add ("D:\flc_Menu\flc-standard.dot"), False
                Unload HovedMenu
                .Activate
            Case Option2.Value
                .Visible = True
                .Documents.Add ("D:\flc_Menu\FLC-Faxskrivelse.dot"), False
                Unload HovedMenu
                .Activate
            Case Option3.Value
                .Visible = True
                .Documents.Add ("D:\flc_Menu\FLC-Flgskrivelse.dot"), False
                Unload HovedMenu
                .Activate
            Case Option4.Value
                .Visible = True
                .Documents.Add ("D:\flc_Menu\FLC-Nord BrugerData.dot"), False
                Unload HovedMenu
                .Activate
        End Select
    End With
End Sub
Avatar billede terry Ekspert
03. juni 2004 - 19:55 #1
You can use the following example to see if word is actually running. I'll see if I can find something onhow to open a new document in the existing instance!
Avatar billede terry Ekspert
03. juni 2004 - 19:55 #2
Avatar billede joern Nybegynder
03. juni 2004 - 20:01 #3
Hej.

Jeg har engang lavet en prototype på en tasklist med basis i noget fri kode fra et site.  Det er i VB5  - til inspiration.  http://jkfsoft.dk/pakker/tasklist.zip

M.v.h.  Jørn
Avatar billede terry Ekspert
03. juni 2004 - 20:16 #4
On Error Resume Next


Set objW = GetObject(, "Word.Application")

If Err = 429 Then 'Not running
    Set objW = CreateObject("Word.Application")

End If

with objW
....
Avatar billede toh Nybegynder
03. juni 2004 - 20:34 #5
Terry det du er kommet frem til virker næsten, men Hvis word er åben schwitcher den ikke over til word men bliver stående på min menu. Jeg skal foretage en aktiv handling for at komme til word. Den skabelon som startes i word har en menu, og når jeg foretager den aktive handling kan jeg kun se menuen og ikke word før jeg har skrevet data i menuen og trykket OK
Avatar billede terry Ekspert
03. juni 2004 - 20:39 #6
doesnt

.visible help?

I'm not sure what you mean with "aktiv handling" or what the menu is doing.

Can you explain some more?
Avatar billede toh Nybegynder
03. juni 2004 - 20:55 #7
Programmet HovedMenu giver mig mulihed for at vælge forskellige Wordtemplates (Letters), disse Wordtemplates indeholder Forms hvor jeg har mulighed for, at indtaste data som bliver indsat i skabelonen(brevet) Når jeg anvender GetObject og Word er åben bliver HovedMenu stående i forgrunden og Word fremkommer med følgende fejlmeddelse "An action can not be completed because a component i not responding" det er hvad jeg mener med en aktiv handling
Avatar billede terry Ekspert
03. juni 2004 - 21:44 #8
This isnt something I have played around with so I'm not sure why Word is giving this error.
It may be an idea to close the current object and then open it again.

If I get a bit of time then I will have a lay around and see if I can find a solution.
Avatar billede terry Ekspert
04. juni 2004 - 18:35 #9
is it possible for you to send me what you have? Its not easy without seeing the exact same problem!
Avatar billede toh Nybegynder
06. juni 2004 - 14:29 #10
Hvor skal jeg sende det til
Avatar billede terry Ekspert
06. juni 2004 - 14:32 #11
eksperten@NOSPAMsanthell.dk

remove NOSPAM
Avatar billede bak Forsker
06. juni 2004 - 14:35 #12
Prøv lige at indsætte disse to linier

objW.Visible = True
objW.UserControl = True
Avatar billede terry Ekspert
06. juni 2004 - 14:47 #13
Yes that might help bak!
Avatar billede terry Ekspert
06. juni 2004 - 14:57 #14
Try this

On Error Resume Next


Set objW = GetObject(, "Word.Application")

If Err = 429 Then 'Not running
    Set objW = CreateObject("Word.Application")

End If

with objW
.Visible = True
.UserControl = True


It may also be a good idea to have a variable which you use to check if it is YOUR application which opened word and if NOT then you do NOT close it.
Avatar billede terry Ekspert
06. juni 2004 - 18:22 #15
this works OK I think

First thing, place this line at the top of each module (form etc.) It makes usre your variables are declared so that you dont get unexpected errors.

Option Explicit


Private Sub cmdOK_Click()
Dim ObjW As Object

    On Error Resume Next
    SetFocus
    Set ObjW = GetObject(, "Word.Application")
    If Err = 429 Then 'Not running
        Set ObjW = CreateObject("Word.Application")
    End If
    With ObjW

        Select Case True
            Case Option1.Value
                '.Visible = True
                .Documents.Add ("D:\flc_Menu\flc-standard.dot"), False
                'Unload HovedMenu
                '.Activate
            Case Option2.Value
                .Visible = True
                .Documents.Add ("D:\flc_Menu\FLC-Faxskrivelse.dot"), False
                Unload HovedMenu
                .Activate
            Case Option3.Value
                .Visible = True
                .Documents.Add ("D:\flc_Menu\FLC-Flgskrivelse.dot"), False
                Unload HovedMenu
                .Activate
            Case Option4.Value
                .Visible = True
                .Documents.Add ("D:\flc_Menu\FLC-Nord BrugerData.dot"), False
                Unload HovedMenu
                .Activate
        End Select
        .Activate
        .Visible = True
        .UserControl = True

    End With
End Sub
Avatar billede terry Ekspert
06. juni 2004 - 19:54 #16
I’ve had another play around with your application and the problem seems to be in the code in your document template, NOT in the VB application!

The UserForm in the template is like a dialog form and it MUST get closed before the code in your VB application continues to run. So the code in the VB application doesn’t have much effect UNTIL the form gets closed. This is obviously a problem when the form is not visible.

The answer to your original question is correct, and would normally work if there was no VBA code in your template, but this is what is stopping the VB program from running.

So I think you need to concentrate on the code in the template. There IS a difference depending on whether the form is, or is not already opened.

I’m not very familiar with Word and VBA so I don’t think I can help so much here.

Mvh
Terry
Avatar billede toh Nybegynder
06. juni 2004 - 20:56 #17
Terry thanks anyway
Avatar billede terry Ekspert
06. juni 2004 - 21:05 #18
thanks to you too.
It may be an idea to have a form in your VB program and then fill in the bookmarks directly from your VB program instead of having the form in Word.

mvh
Terry
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester