Excel vba编程实例 源码

Excel vba编程实例 源码 PrivateSubCommandButton1_Click()AddOneAddNewFourthOneWorksheets(“Sheet2”).ActivateSeveralRowsClearRangeSetValueEnterValueCycleThroughEndSubSubAddOne()Workbooks.AddEndSubSubAddNew()

大家好,又见面了,我是你们的朋友全栈君。 

Private Sub CommandButton1_Click()

‘AddOne

‘AddNew

‘FourthOne

Worksheets(“Sheet2”).Activate

‘SeveralRows

‘ClearRange

‘SetValue

‘EnterValue

CycleThrough

End Sub

Sub AddOne()

Workbooks.Add

End Sub

Sub AddNew()

Set newBook = Workbooks.Add

With newBook

.Title = “1995 Sales”

.Subject = “Sales”

.SaveAs Filename:=”95Sales.xls”

End With

End Sub

Sub FourthOne()

‘AddOne

‘Sheets(3).Activate

‘Charts(1).Activate

‘Charts(“Chart1”).Activate

‘ActiveWorkbook.SaveAs _

‘Filename:=”E:/myfile.htm”, _

‘FileFormat:=xlHtml

‘ChartObjects(1).Activate

‘With Application.DefaultWebOptions

‘.RelyOnVML = True

‘.AllowPNG = True

‘.PixelsPerInch = 96

‘End With

‘With ActiveWorkbook

‘.WebOptions.AllowPNG = False

‘With .PublishObjects(“Chart3”)

‘.Filename = “E:/1998_Q1.htm”

‘.Publish

‘End With

‘End With

End Sub

Sub SeveralRows()

Worksheets(“Sheet2”).Activate

Dim worksheettemp As Worksheet

Set worksheettemp = Worksheets(“Sheet2”)

Dim myUnion As Range

Set myUnion = Union(worksheettemp.Rows(1), worksheettemp.Rows(2), worksheettemp.Rows(5))

myUnion.Font.Bold = True

End Sub

Sub ClearRange()

Worksheets(“Sheet2”).[A1:B5].ClearContents

End Sub

Sub SetValue()

Dim MyRange As Range

Set MyRange = Worksheets(“Sheet2”).[A1:B5]

MyRange.Value = 10

End Sub

Sub EnterValue()

Worksheets(“Sheet2”).Cells(6, 1).Value = 10

End Sub

Sub CycleThrough()

Dim counter As Integer

For counter = 1 To 20

Worksheets(“Sheet2”).Cells(counter, 3).Value = counter

Next counter

End Sub

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/141734.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号