一段word宏,请哪位转一下delphi(在线等)//其实就是画一条装订线 (100分)

  • 主题发起人 主题发起人 lingm
  • 开始时间 开始时间
L

lingm

Unregistered / Unconfirmed
GUEST, unregistred user!
With Selection.Sections(1)
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
With .Borders
.DistanceFrom = wdBorderDistanceFromText
.AlwaysInFront = True
.SurroundHeader = False
.SurroundFooter = False
.JoinBorders = False
.DistanceFromTop = 24
.DistanceFromLeft = 4
.DistanceFromBottom = 24
.DistanceFromRight = 24
.Shadow = False
.EnableFirstPageInSection = True
.EnableOtherPagesInSection = True
.ApplyPageBordersToAllSections
End With
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColor = wdColorAutomatic
End With
End Sub
其实就是画一条页边框,类似装订线
 
不带 with,
Selection 在 delphi 中可以写成 wordapplication1.document.selection
其他的就照着写行了
 
不行[:(]
Undeclared identifier: 'wdBorderLeft'
我用的是CreateOleObject
 
没人[:(]
自己顶
 
别用 CreateOleObject
用 delphi带的office组件,和宏结合用,更方便
 
用惯了
不用控件不行吗?
 
你是不是用ole控件?是的话试试看这段代码可不可以,我随便写的,你可能需要根据实际情况改一下,在你的unit单元的头上的use里还要加入 word2000:

//unit 单元的use里加入word2000,这个是关键,不引用word2000这个单元的话就会出现类似于“Undeclared identifier: 'wdBorderLeft'”的错误

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,word2000;
//unit 单元的use里加入word2000


//加装订线的函数
fuction addline(fn:string):boolean; //fn是你所要对其进行操作的word文件的存储路径
var
wordApp, tempWord: oleVariant; //定义oleVariant类型的变量很关键
begin
TempWord := createoleobject('word.application');
TempWord.documents.add(EmptyParam, false);
TempWord.ActiveDocument.saveAs(fn + 'temp.doc');
tempWord.quit;
TempWord := Unassigned; //oleVariant类型的变量不用后需释放
ole1.CreateObjectFromFile(fn + 'temp.doc', false);
ole1.Run;
WordApp := ole1.OleObject.application;
wordapp.Selection.Sections(1);
wordapp.Borders(wdBorderLeft);
wordapp.LineStyle:=wdLineStyleSingle;
wordapp.LineWidth:=wdLineWidth050pt;
wordapp.Color:=wdColorAutomatic;
wordapp.Borders(wdBorderRight).LineStyle:=wdLineStyleNone;
wordapp.Borders(wdBorderTop).LineStyle:=wdLineStyleNone;
wordapp.Borders(wdBorderBottom).LineStyle:=wdLineStyleNone;
wordapp.Borders;
wordapp.DistanceFrom:=wdBorderDistanceFromText;
wordapp.AlwaysInFront:=True;
wordapp.SurroundHeader:=False;
wordapp.SurroundFooter:=False;
wordapp.JoinBorders:=False;
wordapp.DistanceFromTop:=24;
wordapp.DistanceFromLeft:=4;
wordapp.DistanceFromBottom:=24;
wordapp.DistanceFromRight:=24;
wordapp.Shadow:=False;
wordapp.EnableFirstPageInSection:=True;
wordapp.EnableOtherPagesInSection:=True;
wordapp.ApplyPageBordersToAllSections;
wordapp.Options.DefaultBorderLineStyle:=wdLineStyleSingle;
wordapp.Options.DefaultBorderLineWidth:=wdLineWidth050pt;
wordapp.Options.DefaultBorderColor:=wdColorAutomatic;
WordApp := unAssigned; //oleVariant类型的变量不用后需释放
end;

 
在Word2000.pas当中
你需要在路径当中添加上
$(DELPHI)/Ocx/Servers
 
[:(]
报错
"Sections"不是一种方法
 
你能不能把你那段代码贴出来我看看啊,因为上面那段代码我编译是通过的
 
代码很简单[:)]
procedure TForm1.Button1Click(Sender: TObject);
var
WordApp : OleVariant;
InterfaceVariant: OleVariant;
n:integer;
begin
WordApp := CreateOleObject('Word.Application');
WordApp.Documents.add;
WordApp.ActiveDocument.PageSetup.TextColumns.SetCount(2);

{画一条装订线 }

WordApp.ActiveDocument.PrintPreview;

WordApp.visible:=true;
end;
 
to:wenjun8201
你的代码我是另外新建工程试的
 
在use里还要再引用comobj
 
唉,我再帮你想想啊
 
你有没有邮箱,我有一个VBA For Word 2000 资料.CHM的东东是专门说这方面的东西的你可以看一下
 
后退
顶部