Excel VBA问题 ( 积分: 100 )

  • 主题发起人 主题发起人 q_sand
  • 开始时间 开始时间
Q

q_sand

Unregistered / Unconfirmed
GUEST, unregistred user!
我将
Sub 宏1()
'
' 宏1 Macro
' guo 记录的宏 2007-10-14
'
Range("A1:H1").Select

With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
End Sub
语句转化成
var
Row,Col,FieldIndex :Integer;
BK:TBookMark;
Range, Body,Title, A, B, C, D: Variant;

Title := Sheet.Range['A1:H1'];
Title.Select;
Sheet.Application.Selection.HorizontalAlignment := 'xlCenter';
Sheet.Application.Selection.VerticalAlignment := 'xlBottom';
Sheet.Application.Selection.WrapText := False;
Sheet.Application.Selection.Orientation := 0;
Sheet.Application.Selection.AddIndent := False;
Sheet.Application.Selection.ShrinkToFit := False;
Sheet.Application.Selection.MergeCells := True;
语句,但是说不支持 HorizontalAlignment 属性,请教高手。。。?
 
http://www.star-reg.com/soft/softview.php?id=12543
看下这个软件能否适合你的需要
QQ:292044357
 
procedure lead_excel(ados:TCustomADODataSet;s:string;k:string;da:tdatetime;l:integer);
var
excelapp:variant;
i,j:integer;
save:tsavedialog;
begin
try
save:=tsavedialog.Create(nil);
save.FileName:=s+datetostr(da);
if Save.Execute then
begin
excelapp:=createoleobject('excel.application');
excelapp.workbooks.add;
excelapp.worksheets[1].activate;
excelapp.activesheet.name:=s;
screen.Cursor:=-11;
excelapp.Range['A1:L1'].merge; //合并单元格
excelapp.Range['A1:L1'].value:=s;
excelapp.Range['A1:L1'].HorizontalAlignment:= $FFFFEFF4; //水平居中
excelapp.Range['A1:L1'].font.name:='宋体';
excelapp.Range['A1:L1'].Font.FontStyle:='加粗';
excelapp.Range['A1:L1'].font.size:=18;
excelapp.Range['A1:L1'].Borders.LineStyle:=1 ; //设置边框
excelapp.Range['A2:L2'].merge; //合并单元格
excelapp.Range['A2:L2'].value:=k;
excelapp.Range['A2:L2'].HorizontalAlignment:= $FFFFEFF4; //水平居中
excelapp.Range['A2:L2'].font.name:='宋体';
excelapp.Range['A2:L2'].Font.FontStyle:='加粗';
excelapp.Range['A2:L2'].font.size:=18;
excelapp.Range['A2:L2'].Borders.LineStyle:=1 ; //设置边框
for i:=0 to ados.Fields.count-2 do
begin
ExcelApp.ActiveSheet.Columns[i+1].ColumnWidth := 10; //设置列宽
if i=0 then
ExcelApp.ActiveSheet.Columns[i+1].NumberFormat:='@'
else
ExcelApp.ActiveSheet.Columns[i+1].NumberFormat:='0.00';
excelapp.cells[3,i+1].HorizontalAlignment:= $FFFFEFF4; //水平居中
excelapp.cells[3,i+1].value:=ados.Fields[i+1].FieldName;
excelapp.cells[3,i+1].Borders.LineStyle:=1;
ados.First;
j:=4;
while not ados.Eof do
begin
excelapp.cells[j,i+1].value:=ados.Fields[i+1].Value;
excelapp.cells[j,i+1].Borders.LineStyle:=1;
inc(j);
ados.Next;
end;
end;
screen.Cursor:=0;
excelapp.activesheet.saveas(Save.FileName);
application.MessageBox('导出完成!','消息',0);
excelapp.visible:=false;
excelapp.quit;
save.Free;
end;
except
application.MessageBox('导出发生错误!','消息',16);
end;
end;
 
To chyzpc
我是在讨论如何使用技术,不是想要软件,但对你的热心,表示感谢
 
To shadowpj:
呵呵,可以居中了,但是合并前的文字不见了,但是录制的宏,是不影响文字的,大家再帮下忙吧。
下面是完整的宏
Sub 宏1()
'
' 宏1 Macro
' guo 记录的宏 2007-10-15
'

'
Range("A1:H1").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
End Sub
 
后退
顶部