03. juni 2004 - 19:44Der 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
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!
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
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
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
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.
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
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.
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
Synes godt om
Ny brugerNybegynder
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.