紫薇修真诀,万宝路香烟价格表,韦小宝古今奇缘
dim oexcel,owb,osheet
set oexcel= createobject("excel.application")
set owb = oexcel.workbooks.open("e:\其他\新装电话表.xls")
set osheet = owb.sheets("sheet1")
msgbox osheet.range("b2").value '#提取单元格b2内容
'.....
3、如果是xp系统,可以使用如下代码
dim objfiledlg
set objfiledlg = createobject("useraccounts.commondialog")
objfiledlg.filter = "excel file (*.xls) |*.xls"
if objfiledlg.showopen then
msgbox "您选择的文件是:" & objfiledlg.filename & vbcrlf
end if
vbs控制excel的一些常见方法:
(一) 使用动态创建的方法
首先创建 excel 对象,使用comobj:
oexcel = createobject( "excel.application" )
1) 显示当前窗口:
oexcel.visible = true
2) 更改 excel 标题栏:
oexcel.caption = "应用程序调用 microsoft excel"
3) 添加新工作簿:
oexcel.workbooks.add
4) 打开已存在的工作簿:
oexcel.workbooks.open( "c:\excel\demo.xls" )
5) 设置第2个工作表为活动工作表:
oexcel.worksheets(2).activate
或
oexcel.workssheets( "sheet2" ).activate
6) 给单元格赋值:
oexcel.cells(1,4).value = "第一行第四列"
7) 设置指定列的宽度(单位:字符个数),以第一列为例:
oexcel.activesheet.columns(1).columnswidth = 5
8) 设置指定行的高度(单位:磅)(1磅=0.035厘米),以第二行为例:
oexcel.activesheet.rows(2).rowheight = 1/0.035 ' 1厘米
9) 在第8行之前插入分页符:
oexcel.worksheets(1).rows(8).pagebreak = 1
10) 在第8列之前删除分页符:
oexcel.activesheet.columns(4).pagebreak = 0
11) 指定边框线宽度:
oexcel.activesheet.range( "b3:d4" ).borders(2).weight = 3
1-左 2-右 3-顶 4-底 5-斜( \ ) 6-斜( / )
12) 清除第一行第四列单元格公式:
oexcel.activesheet.cells(1,4).clearcontents
13) 设置第一行字体属性:
oexcel.activesheet.rows(1).font.name = "隶书"
oexcel.activesheet.rows(1).font.color = clblue
oexcel.activesheet.rows(1).font.bold = true
oexcel.activesheet.rows(1).font.underline = true
14) 进行页面设置:
a.页眉:
oexcel.activesheet.pagesetup.centerheader = "报表演示"
b.页脚:
oexcel.activesheet.pagesetup.centerfooter = "第&p页"
c.页眉到顶端边距2cm:
oexcel.activesheet.pagesetup.headermargin = 2/0.035
d.页脚到底端边距3cm:
oexcel.activesheet.pagesetup.headermargin = 3/0.035
e.顶边距2cm:
oexcel.activesheet.pagesetup.topmargin = 2/0.035
f.底边距2cm:
oexcel.activesheet.pagesetup.bottommargin = 2/0.035
g.左边距2cm:
oexcel.activesheet.pagesetup.leftmargin = 2/0.035
h.右边距2cm:
oexcel.activesheet.pagesetup.rightmargin = 2/0.035
i.页面水平居中:
oexcel.activesheet.pagesetup.centerhorizontally = 2/0.035
j.页面垂直居中:
oexcel.activesheet.pagesetup.centervertically = 2/0.035
k.打印单元格网线:
oexcel.activesheet.pagesetup.printgridlines = true
15) 拷贝操作:
a.拷贝整个工作表:
oexcel.activesheet.used.range.copy
b.拷贝指定区域:
oexcel.activesheet.range( "a1:e2" ).copy
c.从a1位置开始粘贴:
oexcel.activesheet.range.( "a1" ).pastespecial
d.从文件尾部开始粘贴:
oexcel.activesheet.range.pastespecial
16) 插入一行或一列:
a. oexcel.activesheet.rows(2).insert
b. oexcel.activesheet.columns(1).insert
17) 删除一行或一列:
a. oexcel.activesheet.rows(2).delete
b. oexcel.activesheet.columns(1).delete
18) 打印预览工作表:
oexcel.activesheet.printpreview
19) 打印输出工作表:
oexcel.activesheet.printout
20) 工作表保存:
if not oexcel.activeworkbook.saved then
oexcel.activesheet.printpreview
21) 工作表另存为:
oexcel.saveas( "c:\excel\demo1.xls" )
22) 放弃存盘:
oexcel.activeworkbook.saved = true
23) 关闭工作簿:
oexcel.workbooks.close
24) 退出 excel:
oexcel.quit
(二) 使用vbs 控制excle二维图
1)选择当第一个工作薄第一个工作表
set osheet=oexcel.workbooks(1).worksheets(1)
2)增加一个二维图
achart=osheet.chartobjects.add(100,100,200,200)
3)选择二维图的形态
achart.chart.charttype=4
4)给二维图赋值
set series=achart.chart.seriescollection
range="sheet1!r2c3:r3c9"
series.add range,true
5)加上二维图的标题
achart.chart.hastitle=true
achart.chart.charttitle.characters.text=" excle二维图"
6)改变二维图的标题字体大小
achart.chart.charttitle.font.size=18
7)给二维图加下标说明
achart.chart.axes(xlcategory, xlprimary).hastitle = true
achart.chart.axes(xlcategory, xlprimary).axistitle.characters.text = "下标说明"
8)给二维图加左标说明
achart.chart.axes(xlvalue, xlprimary).hastitle = true
achart.chart.axes(xlvalue, xlprimary).axistitle.characters.text = "左标说明"
9)给二维图加右标说明
achart.chart.axes(xlvalue, xlsecondary).hastitle = true
achart.chart.axes(xlvalue, xlsecondary).axistitle.characters.text = "右标说明"
10)改变二维图的显示区大小
achart.chart.plotarea.left = 5
achart.chart.plotarea.width = 223
achart.chart.plotarea.height = 108
如何用vbs把excel的单元格数据写到txt
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
网友评论