Autor Beitrag
jome
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 29

Win 2000, XP, VISTA, WIN 7
Delphi 4,5, 2006 Pro., 2007 Pro., Delphi XE
BeitragVerfasst: Mi 28.01.09 13:00 
Hallo zusammen,

was müsste Eurer Erfahrung nach für ein Problem auf dem PC des Kunden vorliegen, wenn der folgende Code die Message auslöst, dass MS Word nicht verbunden werden konnte:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
Try
 WordApplication1.Connect;
Except
 ShowMessage('Could not connect MS Word!');
End;


Die entsprechende Komponente WordApplication1 befindet sich auf einem leeren Form. Eingebunden ist die Unit WORD2000.

Beim Kunden liegt vor:
WinXP Professional
WORD 2003 SP 3

Mein Compiler: Delphi 2007

Gruß
Jo
zuma
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 660
Erhaltene Danke: 21

Win XP, Win7, Win 8
D7 Enterprise, Delphi XE, Interbase (5 - XE)
BeitragVerfasst: Mi 28.01.09 13:32 
hab da mal was gemacht, um Doc's als Tif zu speichern, evtl. hilft dir davon was weiter

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
function gibWordApp(xVisible : boolean = false) : TWordApplication;
begin
 try
  result := TWordApplication.Create(nil);                 // Word im Hintergrund starten
  result.Visible:= xVisible;             
 except
  result := nil;
 end;
end;


function docListe2Tif(xDocPfad : String; xTifPfad : String; xDateiliste : TStringlist; xTifName : String = '') : integer;
var OleFileName, OleTifName, OlePrinterName, OleCopies, SaveChanges : OleVariant;
    FWord            : TWordApplication;                     // Wordapplikation
    FDocument        : TWordDocument;                        // Worddokument
    datname, drucker : String;
    i                : integer;
begin
 result := dkOKDone;
 // Übergabeparameter prüfen
 if (xDocPfad = '') then         result := dkNoDocPath;
 if (xDateiliste.Count < 1) then result := dkNoFileListGiven;
 if (xTifPfad = '') then         result := dkNoTifPath;
 if (Result = dkOKDone) then                                 // Parameter angegeben
 begin
  try
   FWord := gibWordApp(False);
   FDocument := TWordDocument.Create(nil);                   // Dokument erzeugen
   SaveChanges := wdDoNotSaveChanges;             // Option 'nicht speichern' einstellen
   oleCopies := 1;                                           // Anzahl Kopien
  except
   result := dkWordNotFound;                                 // Fehler geben
  end;
  if (result = dkOKDone) then                                // Word da und offen
  begin
   try
    olePrinterName := MsOffImageDrucker;                   // Druckername
    drucker := FWord.ActivePrinter;
    FWord.ActivePrinter := olePrinterName;          // aktiven Drucker in Word setzen
   except
    result := dkTifPrinterNotFound;                             // Fehler geben
   end;
   if (result = dkOKDone) then
   begin
    try
     try
      for i := 0 to xDateiliste.Count-1 do         // alle Dateien durchlaufen
      begin
       datname     := xDateiliste.Strings[i];      // Dateiname auslesen
       OleFileName := xDocPfad + datname;    // DokumentenPfad(kompletter Pfad/Dateiname)
       if (xTifName = '') then
       begin
        OleTifName  := xTifPfad +             // (Pfad Tif-datei)
                   copy(datname,0,length(datname)-3)+ // Dateiname des Bildes = Dokname
                        'tif';                        // mit Endung 'tif'
       end
       else
        OleTifName := xTifName + '.tif';              // Tifname vorgeben (Artnr)
       if istDocNeuerAlsTif(OleFileName, OleTifName) then
       begin
        FWord.Documents.OpenOld( OleFileName, EmptyParam, EmptyParam, // Dokument öffnen
                                 EmptyParam, EmptyParam, EmptyParam,
                                 EmptyParam, EmptyParam, EmptyParam,
                                 EmptyParam);
        FDocument.ConnectTo(FWord.ActiveDocument);             // mit Dokument verbinden
      FDocument.PrintOut( emptyParam,emptyParam,emptyParam{#Range},  // Dokument drucken
                            OleTifName{OutFileName},            // Name des Bildes
                            emptyPAram{From},emptyParam{To_},
                            emptyParam,oleCopies,              // Anzahl Kopien
                            EmptyParam,emptyParam,emptyParam);
        while (FWord.BackgroundPrintingStatus > 0) do
        begin
         Sleep(500);                         // halbe sekunde auf 'Druck fertig' warten
        end;
 FWord.ActiveDocument.Close(SaveChanges, EmptyParam, EmptyParam);  // Dokument schliessen
        FDocument.Disconnect;                     // Verbindung zum Dokument aufheben
       end;
      end;
     except
      result := dkTifPrinterError;                // Fehlernr geben
     end;
    finally
    FDocument.Free;                              // Dokument freigeben
    FWord.ActivePrinter := drucker;             // Drucker zurücksetzen
    FWord.Disconnect;                           // Verbindung zu Word trennen
    FWord.Quit(SaveChanges, EmptyParam, EmptyParam);    // Word schliessen
    FWord.Free;                                        // Speicher freimachen
 end;
   end;
  end;
 end;
end;

_________________
Ich habe nichts gegen Fremde. Aber diese Fremden sind nicht von hier! (Methusalix)
Warum sich Sorgen ums Leben machen? Keiner überlebts!
jome Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 29

Win 2000, XP, VISTA, WIN 7
Delphi 4,5, 2006 Pro., 2007 Pro., Delphi XE
BeitragVerfasst: Mi 28.01.09 14:25 
Hallo zuma,

danke, aber wie reagiert Dein Programm wenn Deine Zeilen

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
function gibWordApp(xVisible : boolean = false) : TWordApplication;
begin
 try
  result := TWordApplication.Create(nil);                 // Word im Hintergrund starten
  result.Visible:= xVisible;             
 except
  result := nil;
 end;
end;


ein NIL zurückgeben? Kennst Du den Grund dafür?

Gruß
jo


Zuletzt bearbeitet von jome am Mi 28.01.09 14:28, insgesamt 1-mal bearbeitet
Regan
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2157
Erhaltene Danke: 72


Java (Eclipse), Python (Sublimetext 3)
BeitragVerfasst: Mi 28.01.09 14:27 
Ich hatte mal ein ähnliches Problem. Ich glaube, es lag damals daran, dass die Delphi-Unit nur abwärtskompatibel ist. Bei mir war es, glaube ich, Office XP. Aber das ist rein spekulativ, da ich mich nur sehr vage daran erinnern kann. Vielleicht hilft das aber weiter.


Zuletzt bearbeitet von Regan am Mi 28.01.09 14:45, insgesamt 1-mal bearbeitet
zuma
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 660
Erhaltene Danke: 21

Win XP, Win7, Win 8
D7 Enterprise, Delphi XE, Interbase (5 - XE)
BeitragVerfasst: Mi 28.01.09 14:37 
hmm, Regan sagt da was ..
irgendwas hab ich da auch noch im Hinterkopf, das nicht alle Word-Versionen kompatibel waren ...
Weiss aber leider auch nicht mehr genau, welche Kompatibel waren bzw. wie die neueren anzusprechen sind (hatte damals die Units Word97 und Word2000 eingebunden).

_________________
Ich habe nichts gegen Fremde. Aber diese Fremden sind nicht von hier! (Methusalix)
Warum sich Sorgen ums Leben machen? Keiner überlebts!