如何用VBA获取当前页页码.docx
《如何用VBA获取当前页页码.docx》由会员分享,可在线阅读,更多相关《如何用VBA获取当前页页码.docx(16页珍藏版)》请在冰点文库上搜索。
如何用VBA获取当前页页码
如何用VBA获取当前页页码
x=executeexcel4macro("get.document(50)")
achart.chart.seriescollection[1].name:
='坐标轴申明';
b.页脚:
excelapplication1.activesheet.range['b3:
d4'].borders[2].weight:
=3;
begin
excelapplication1.activesheet.columns[1].columnswidth:
=5;
dimnumpageasinteger
10)配置指定行的高度(单位:
磅)(1磅=0.035厘米),以第二举动例:
nexthpb
onerrorresumenext
excelapp.workbooks.open('c:
\excel\do.xls');
msgbox"今朝存储格在第"&numpage&"页"
excelapp:
=createoleobject('excel.application');
endif
8)给二维图加左标申明
numpage=numpage+vpc
achart.chart.axes(xlcategory,xlprimary).axistitle.characters.text:
='下标申明';
16)插进去一行或者一列:
excelapplication1.activesheet.rows[1].font.underline:
=true;
excelapplication1.worksheets[2].activate;或者
excelapp.activeworkbook.saved:
=true;
e.顶边距2cm:
j.页面铅直居中:
activewindow.view=xlpagebreakpreview
ifvpb.location.column>activecell.columnthenexitfor
25)封闭事情簿:
excelapplication1.activesheet.printpreview;
achart.chart.axes(xlvalue,xlsecondary).hastitle:
=true;
11)给二维图坐标轴加之申明
excelapplication1.worksheets[1].rows[8].pagebreak:
=1;
else
c.从a1位置起头粘附:
或者
ifactivesheet.pagesetup.order=xldownthenoverthen
14)断根熬头行第四列单位格公式:
f.底边距2cm:
在form中别离放入excelapplication,excelworkbook以及excelworksheet
ifexecuteexcel4macro("get.document(50)")=0then
sub逆页序打印()
用vba本人只懂患上总页码儿的要领,时下页码儿就难倒我了,还请vba妙手指头教
(三)施用delphello节制excle二维图
executeexcel4macro("print(2,"&2*j&","&2*j&",1,,,,,,,,2,,,true,,false)")
i.页面程度居中:
achart.chart.charttitle.characters.text:
=’excle二维图’
nextvpb
13)指定边框线宽度:
vb以及vba常识2010-09-1417:
57:
46阅览11品题0字号:
大中小定阅=if(iserror(match(row(),get.document(64),1)),1,match(row(),get.document(64),1)+1)=if(isna(match(column(),get.document(65))),1,match(column(),get.document(65))+1)
achart.chart.plotarea.width:
=223;
12)在第8列以前删去分页符:
msgbox"请将打印纸逆向装入打印机中",vbokonly,"打印另外一壁"
="第"&if(横当页=1,纵当页,横当页+纵当页)&"页/共"&总页&"页"
要领一,用vba
foreachvpbinactivesheet.vpagebreaks
achart:
=asheet1.chartobjects.add(100,100,200,200);
nexti
11)在第8行以前插进去分页符:
excelapplication1.saveas('c:
\excel\do1.xls');
<
g.左面距2cm:
endfunction
excelapplication1.activesheet.printpreview;
3)新增新事情簿:
endsub
19)打印输出事情表:
dimhpcasinteger
excelapp.activesheet.pagesetup.topmargin:
=2/0.035;
excelapplication1.activesheet.pagesetup.headermargin:
=2/0.035;
endsub
excelapp.activesheet.printout;
纵向activesheet.vpagebreaks.count+1
achart.chart.axes(xlvalue,xlprimary).hastitle:
=true;
4.最后再新增第4个名称,再输入:
“页眉”,援用位置:
functionpage()
7)给二维图加下标申明
ptyparam,ptyparam,ptyparam,ptyparam,
要领二,用宏表函数与公式
subprintactivepage()
j.页面铅直居中:
2.之后再接续新增第二个名称:
“横当页”,鄙人面援用位置处输入:
vpc=activesheet.vpagebreaks.count+1
23)事情表另存为:
2)增长1个二维图
end;
c.从a1位置起头粘附:
series.add(range,true);
excelapp.worksheets[2].activate;
fori=xto1step-1
a.excelapp.activesheet.rows[2].insert;
excelapplication1.caption:
='应用步伐挪用microsoftexcel';
(二)施用delphello控件要领
achart.chart.hastitle:
=true;
excelapplication1.activesheet.rows[1].font.color:
=clblue;
excelapplication1.activesheet.printout;
c.页眉到顶点端边距2cm:
excelapp.activesheet.printpreview;
在excel中配置第几页共几页,绝大部门人会想道用“页面配置”,但你是不是想过将“第n页/总m页”放到肆意单位格中?
而不仅只是置于页眉页脚中?
excelapp.activesheet.rows[1].font.name:
='隶字';
16)举行页面配置:
hpc=activesheet.hpagebreaks.count+1
excelapplication1.activeworkbook.saved:
=true;
excelworksheet1.connectto(tp_worksheet);
excelapp.activesheet.rows[1].font.bold:
=true;
5.选中需要预示页码儿的单位格,并在单位格输入这个公式:
="第"&if(横当页=1,纵当页,横当页+纵当页)&"页/共"&总页&"页",便可获患上需要的页码儿
要领二,用宏表函数与公式
excelapplication1.activesheet.pagesetup.bottommargin:
=2/0.035;
5.在函数栏施用应用便可获患上需要的页码儿预示时下页码儿以及勾当文档的总页数:
msgbox"theselectionisonpage"&_selection.information(wdactiveendpagenumber)&"ofpage"_&selection.information(wdnumberofpagesindocument
e.顶边距2cm:
=get.document(50)+随机()*0
4)给二维图赋值
msgbox"今朝存储格在第"&numpage&"页"
21)事情表另存为:
二、在文本框中界说1个名称(好比“pagenumber”),新增后鄙人面的“援用位置”中输入“=if(iserror(match(row(),get.document(64),1)),1,match(row(),get.document(64),1)+1)”(不含双引号,下同),确定撤退退却出;
b.excelapp.activesheet.columns[1].insert;
excelapplication1.activesheet.range.pastespecial;
在excel中把页码儿插进去到除页眉页脚外的肆意单位格中
page=(activesheet.hpagebreaks.count+1)*(activesheet.vpagebreaks.count+1)
sub奇偶页打印()
18)打印预览事情表:
excelapplication1.activesheet.used.range.copy;
ifintersect(activesheet.usedrange,activecell)isnothellongthen
endif
executeexcel4macro("print(2,"&2*i-1&","&2*i-1&",1,,,,,,,,2,,,true,,false)")
else
excelapplication1.activesheet.pagesetup.centerhorizontally:
=2/0.035;
用vba本人只懂患上总页码儿的要领,时下页码儿就难倒我了,还请vba妙手指头教
2010年09月14日
series:
=achart.chart.seriescollection;
1.起首,按ctrl+f3组合键打开界说名称,再在上边输入“纵当页”,鄙人面援用位置处输入:
=get.document(50)+随机()*0
forj=1toint(x/2)+1
next
获取sheet打印页码儿代码:
26)退出excel:
numpage=1
5)配置第二个事情表为勾当事情表:
excelapp.activesheet.pagesetup.centervertically:
=2/0.035;
excelapplication1.quit;
=if(isna(match(column(),get.document(65))),1,match(column(),get.document(65))+1)
dimvpbasvpagebreak
page=(activesheet.hpagebreaks.count+1)*(activesheet.vpagebreaks.count+1)
3.再输入“总页”;援用位置处输入:
achart.chart.charttype:
=4;
numpage=numpage+vpc
4.最后再界说“页眉”,援用位置:
exitsub
excelapp.activesheet.range.['a1'].pastespecial;
9)在第8行以前插进去分页符:
b.页脚:
excelapplication1.activesheet.rows[1].font.bold:
=true;
excelapplication1.activesheet.columns[4].pagebreak:
=0;
ifnotexcelapp.activeworkbook.savedthen
varasheet1,achart,range:
variant;
c.页眉到顶点端边距2cm:
excelapp.activesheet.pagesetup.centerheader:
='报演出示';
13)配置熬头行字体属性:
15)配置熬头行字体属性:
fori=1toint(x/2)+1
'先判断编页码儿的挨次也就是版面设定的循栏列印或者循列列印
'取患上页数后再判断今朝存储格是不是在列印规模中
nextj
excelworkbook1.connectto(excelapplication1.workbooks.add(ptyparam,0));
4)新增新事情簿:
1)预示时下窗户:
ifactivesheet.pagesetup.order=xldownthenoverthen
application.screenupdating=true
excelapp.activesheet.printpreview;
excelapp.quit;
在form中别离放入excelapplication,excelworkbook以及excelworksheet
vpc=1
起首始于excel对于象,施用comobj:
excelapplication1.activesheet.range['a1:
e2'].copy;
hpc=1
h.右面距2cm:
endif
application.screenupdating=true
ptyparam,ptyparam,ptyparam,ptyparam,0)
activewindow.view=xlnormalview
24)抛却保存到磁盘:
a.excelapplication1.activesheet.rows[2].delete;
endsub
excelapp.saveas('c:
\excel\do1.xls');
=if(isna(match(row(),get.document(64))),1,match(row(),get.document(64))+1)
b.excelapp.activesheet.columns[1].delete;
excelapplication1.workbooks.open(c:
\a.xls
三、往后在需要的单位格中输入“=pagenumber”便可迅速获患上时下页码儿数
7)配置指定列的宽度(单位:
字符个数),以熬头列为例:
2.之后再接续新增第二个名称:
“横当页”,鄙人面援用位置处输入:
22)事情表生存:
excelapp.activesheet.rows[1].font.underline:
=true;
k.打印单位格网线:
18)插进去一行或者一列:
22)抛却保存到磁盘:
a.excelapp.activesheet.rows[2].delete;
numpage=1
11)指定边框线宽度:
excelapplication1.activesheet.pagesetup.topmargin:
=2/0.035;
9)给二维图加右标申明
17)删去一行或者一列:
x=executeexcel4macro("get.document(50)")
excelapp.visible:
=true;
a.复印全般事情表:
achart.chart.axes(xlcategory,xlprimary).hastitle:
=true;
10)转变二维图的预示区巨细
excelapp.workssheets['sheet2'].activate;
application.volatile
1-左2-右3-顶4-底5-斜(\)6-斜(/)
exitsub
vpc=1
a.excelapplication1.activesheet.rows[2].insert;
range:
=sheet1!
r2c3:
r3c9;
worksheets.add(ptyparam,ptyparam,ptyparam,ptyparam,0)as_worksheet;
b.复印指定地区范围:
2)更改excel标题栏:
excelapplication1.activesheet.range.['a1'].pastespecial;
24)退出excel:
d.从文件尾部起头粘附:
excelapplication1.activesheet.pagesetup.centervertically:
=2/0.035;
msgbox"excel找不到打印的内部实质意义"
activewindow.view=xlnormalview
在excel的统一事情薄中中,我有两张事情表,一张为日生产进度报表,另外一张为周刊表.我需要用一样的宏语言使成为事实双面打印.但不知怎样计数我用鼠标点这儿的日子处,分页符摆列第几?
常识点:
哄骗宏表函数get.document来获恰时下打印的总页数,再哄骗pagesetup.order(打印的秩序序)、hpagebreaks(程度分页符的调集)、vpagebreaks(铅直分页符的调集)等属性,来算出activecell(时下单位格)的页码儿
20)事情表生存:
excelapp.caption:
='应用步伐挪用microsoftexcel';
b.excelapplication1.activesheet.columns[1].insert;
要领一,用vba
8)给单位格赋值:
2)预示时下窗户:
endif
vpc=activesheet.vpagebreaks.count+1
msgbox"excel找不到列印的内部实质意义"
application.volatile
1-左2-右3-顶4-底5-斜(\)6-斜(/)
ptyparam,ptyparam,ptyparam,ptyparam,
1.起首:
点ctrl+f3打开界说名称,再在上边输入“纵当页”,鄙人面援用位置处输入:
activewindow.selectedsheets.printoutfrom:
=i
f.底边距2cm:
d.页脚到尽头端边距3cm:
17)复印操作:
ifx=0then
endif
excelapp.activesheet.pagesetup.rightmargin:
=2/0.035;
-*******--------------**********************
msgbox"今朝存储格不在列印规模中"
i.页面程度居中:
excelapplication1.workssheets['sheet2'].activate;
achart.chart.plotarea.left:
=5;
achart.chart.axes(xlvalue,xlprimary).axistitle.characters.text:
='左标申明';
exitsub
excelapp.activesheet.pagesetup.bottommargin:
=2/0.035;
1)选择当熬头个事情薄熬头个事情表
而在excel2007中则在东西面板上切换到“公式”选项下,在“界说的名称”选项组中点这儿“界说名称”后的下拉箭头,选择“界说名称”后一样打开“新建名称”会话框,余下的操作跟前边的excel2003不异
excelapplication1.activesheet.rows[2].rowheight:
=1/0.035;//1厘米
g.左面距2cm:
excelapp.activesheet.cells[1,4].clearcontents;
横向activesheet.hpagebreaks.count+1
activewindow.view=xlpagebreakpreview
vartp_worksheet:
_worksheet;
application.screenupdating=true
excelapplication1.visible[0]:
=true;
7)配置第二个事情表为勾当事情表:
k.打印单位格网线:
else
咱们在excel多页生产进度报表打印输出时,要是需要明确某个单位格数值地点的页码儿,即把页码儿放在肆意单位格中,在excel中配置第几页共几页或者页码儿,绝大部门人会想道用“页面配置”,但你是不是想过将“第n页/总m页”或者页码儿放到肆意单位格中?
而不仅只是置于页眉页脚中?
excelapplication1.activesheet.rows[1].font.name:
='隶字';
*********************
6)打开已经存在的事情簿:
excelapp.activesheet.pagesetup.centerhorizontally:
=2/0.035;
14)举行页面配置:
excelapplication1.cells[1,4].value:
='熬头行第四列';
endsub
要领三、用函数使成为事实
d.页脚到尽头端边距3cm:
6)给单位格赋值:
ifvpb.location.column>activecell.columnthenexitfor
excelapp.activesheet.range['a1:
e2'].copy;
10)在第8列以前删去分页符:
ifintersect(activesheet.usedrange,activecell)isnothellongthen
a.页眉:
dimhpbashpagebreak
nexthpb
excelapp.workbooks.add;
excelapp.worksheets[1].rows[8].pagebreak:
=1;
endfunction
functionpage()
excelapp.activesheet.range.pastespecial
ifhpb.location.row>activecell.rowthenexitfor
excelapplication1.disconnect;
b.excelapplication