Autor Beitrag
haribert
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Win 98 SE, Win 2000, Win XP
Delphi 5 prof. Delphi 7 prof.
BeitragVerfasst: Fr 24.02.06 12:12 
Hallo,

ich hab da mal ne Frage: Ich will mit Word aus Delphi heraus ein neues Worddokument erstellen und das dann formatieren.

Der Wordzugriff selber funktioniert auch gut, ich hab auch schon mal einen Serienbrief erstellt, der mit einer Vorlage arbeitet etc., was ich aber nicht hinbekomme ist per MSWord.ActiveDocument.PageSetup(....) die Seite z.B. auf Quer zu formatieren. Es kommt dann jedesmal "PageSetup wird von Automatisierungsobjekt nicht unterstützt"

Weiß da jemand einen Rat? Alles andere was ich brauche - Tabelle erstellen etc. hab ich hinbekommen nur am PageSetup scheitere ich noch.

Gruß
Uwe

_________________
Dieser Beitrag besteht aus 100% recyclingfähigen und glücklichen Elektronen!
Watsch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 97

Win98 SE
D3 Prof, D4 C/S
BeitragVerfasst: So 26.02.06 18:52 
Hi.
Kannst Du vielleicht mal einen Code-Schnipsel posten. Vielleicht kann ich Dir da helfen.

MfG Watsch
haribert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Win 98 SE, Win 2000, Win XP
Delphi 5 prof. Delphi 7 prof.
BeitragVerfasst: Mi 01.03.06 17:07 
Hallo Watsch,

hier mein Code - ist etwas länger geworden, aber ich hoffe, daß man das Problem erkennen kann:

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:
procedure Tadressen.Expo1;
const wdCatalog=3;         // aus VBA-Hilfe - anders wird die Serienbrieffunktion CATALOG nicht angenommen
var       MSWord:                                                   OLEVariant;
          wdWord9TableBehavior, wdAutoFitFixed, Selection:          OLEVariant;
          wdMergeSubTypeAccess, wdSendToNewDocument, bastel_kat:    OLEVariant;
begin
     // Ausgabe als Wordliste
     if ComboBox2.Text='Word-Liste' then
     begin
          try                
             MSWord:=CreateOleObject('Word.Application');
          except
             ShowMessage('Kann WinWord nicht starten!');
             Exit;
          end;
          MSWord.Visible:=true; 
          MSWord.Documents.Add;   // Neues Dokument
          MSWord.ActiveDocument.MailMerge.MainDocumentType:=wdCatalog;  // Word-Liste




    // Problem Anfang - Das hier funktioniert einfach nicht :-((
          MSWord.ActiveDocument.PageSetup(Orientation:=wdOrientLandscape);
          // Problem Ende



          // Tabelle mit 6 Spalten anlegen - funktioniert einwandfrei
          MSWord.ActiveDocument.Tables.Add(Range:=MSWord.Selection.Range, NumRows:=1,
                  NumColumns:=6, DefaultTableBehavior:=wdWord9TableBehavior,
                  AutoFitBehavior:=wdAutoFitFixed);

    // Ein Beispiel mit einer Datenbank namens expo.dbf
          sTargetFile:=ExtractFilePath(Application.ExeName)+'expo.dbf';
          sFilePath:=ExtractFilePath(Application.ExeName);
          zwi:='DSN=dBASE-Dateien;DBQ='+sFilePath+';DefaultDir='+sFilePath+
              ';DriverId=533;MaxBufferSize=512;PageTimeout=5;';

          MSWord.ActiveDocument.MailMerge.OpenDataSource(Name:=sTargetFile, // Mischvorgang - Datenquelle öffnen
              ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True,
              AddToRecentFiles:=False, PasswordDocument:='', PasswordTemplate:='',
              WritePasswordDocument:='', WritePasswordTemplate:='', Revert:=False,
              Format:=wdOpenFormatAuto, Connection:=zwi,
              SQLStatement:='SELECT * FROM `EXPO`', SQLStatement1:='', SubType:= wdMergeSubTypeAccess);

          // Übergabe von Seriendruckfelder als Beispiel wie folgt:
          MSWord.ActiveDocument.MailMerge.Fields.Add(Range:=MSWord.Selection.Range ,Name:='NAME2');
          MSWord.Selection.MoveRight;

          // SQL-Selektion übergeben und ausführen - funktioniert alles einwandfrei
          MSWord.ActiveDocument.MailMerge.Destination:=wdSendToNewDocument;
          MSWord.ActiveDocument.MailMerge.SuppressBlankLines:=true;
          MSWord.ActiveDocument.MailMerge.DataSource.QueryString:='SELECT * FROM `EXPO` ';
          MSWord.ActiveDocument.MailMerge.Execute;
     end;
end;



Ich hab jetzt bestimmt beim zusammenkürzen irgendwelche Variablen in der var-Deklaration mitentfernt, die aber für das Problem unerheblich sind. Ich kann einfach nicht glauben, daß komplizierte Vorgänge wie im Rest des Scripts, Tabelle anlegen, mischen etc. funktionieren sollen, ein einfaches Umstellen des Worddokumentes auf quer aber nicht. Ich würde mich freuen, wenn Dir da was einfällt, ich komm da im Moment einfach nicht weiter.

Viele Grüße
Uwe

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt

_________________
Dieser Beitrag besteht aus 100% recyclingfähigen und glücklichen Elektronen!
Watsch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 97

Win98 SE
D3 Prof, D4 C/S
BeitragVerfasst: Mi 01.03.06 18:14 
Hi.

Dein Problem ist ja folgendes:
ausblenden Delphi-Quelltext
1:
MSWord.ActiveDocument.PageSetup(Orientation:=wdOrientLandscape);					


Ich glaube, das Problem ist, das ActiveDocument das Objekt PageSetup tatsächlich nicht unterstützt, daher auch Deine Fehlermeldung. Ich habe es mal wie folgt probiert, und es funktioniert einwandfrei:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm1.Button1Click(Sender: TObject);
var
  MSWord: Variant;
begin
  try
    MSWord := CreateOleObject('Word.Application');
  except
    ShowMessage('Konnte M$Word nicht starten.');
    Exit;
  end;

  MSWord.Visible := True;
  // ein neues Dokument erzeugen
  MSWord.Documents.Add;
  // Ansicht
  MSWord.ActiveWindow.ActivePane.View.Type := 3;
  // 0 = wdPortrait, 1 = wdLandScape
  MSWord.Selection.PageSetup.Orientation := 1;
end;


Wie Du hier sehen kannst, musst Du wohl über Selection auf PageSetup zugreifen, und kannst dann über die Zahlen 0 (Hochformat) oder 1 (Querformat) das Seitenlayout einstelen.

Mfg Watsch

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt
haribert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Win 98 SE, Win 2000, Win XP
Delphi 5 prof. Delphi 7 prof.
BeitragVerfasst: Do 02.03.06 10:37 
Hallo Watsch,

vielen herzlichen Dank für den Hinweis - habs gleich ausprobiert und jetzt funktioniert die gesamte Ausgabe so wie sie soll - in Querdruck!

Viele Grüße
Uwe

_________________
Dieser Beitrag besteht aus 100% recyclingfähigen und glücklichen Elektronen!