Excel vba编程实例 源码

 
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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
OfficeTips Home || VBA Section || General Section || Download Section || Privacy Policy Useful PowerPoint VBA code snippets More Sharing Services Share | Share on gmail Share on google Share on facebook Share on twitter Determine the current slide in the Slide View mode: Sub SlideIDX() MsgBox "The slide index of the current slide is:" & _ ActiveWindow.View.Slide.SlideIndex End Sub Determine the current slide in Slide Show mode: Sub SlideIDX() MsgBox "The slide index of the current slide is:" & _ ActivePresentation.SlideShowWindow.View.Slide.SlideIndex End Sub Difference between SlideIndex property and SlideNumber property: The SlideIndex property returns the actual position of the slide within the presentation. The SlideNumber property returns the PageNumber which will appear on that slide. This property value is dependent on "Number Slide from" option in the Page Setup. Go to Page Setup and Change the value of "Number Slide from" to 2 and then while on the 1st slide in Slide View run the following Macro Sub Difference() MsgBox "The Slide Number of the current slide is:" & _ ActiveWindow.View.Slide.SlideNumber & _ " while the Slide Index is :" & _ ActiveWindow.View.Slide.SlideIndex End Sub Macro to exit all running slide shows: Sub ExitAllShows() Do While SlideShowWindows.Count > 0 SlideShowWindows(1).View.Exit Loop End Sub Code to refresh current slide during the slide show: Sub RefreshSlide() Dim lSlideIndex As Long lSlideIndex = SlideShowWindows(1).View.CurrentShowPosition SlideShowWindows(1).View.GotoSlide lSlideIndex End Sub Code to reset animation build for the current slide during the slide show: Sub ResetSlideBuilds() Dim lSlideIndex As Long lSlideIndex = SlideShowWindows(1).View.CurrentShowPosition SlideShowWindows(1).View.GotoSlide lSlideIndex, True End Sub Insert a slide after current slide Sub InsertSlide() Dim oView As View With ActivePresentation.Slides Set oView = ActiveWindow.View oView.GotoSlide .Add(oView.Slide.SlideIndex + 1, _ ppLayoutTitleOnly).SlideIndex Set oView = Nothing End With End Sub Copyright 1999-2011 (c) Shyam Pillai. All rights reserved.
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值