yhd-VBA转VB.Net VSTO学习记录-1
想搞个插件
'显示当前文本
Private Sub Button1_Click(sender As Object, e As RibbonControlEventArgs) Handles Button1.Click
MsgBox(xlapp.ActiveCell.Value)
End Sub
'打开文件
Private Sub Button2_Click(sender As Object, e As RibbonControlEventArgs) Handles Button2.Click
Dim yhdfile As String '= "C:\Users\Admin\Desktop\test\拆分源test.xlsx"
With OpenFileDialog1
.Filter = "Excel文件|*.xls*"
.Multiselect = False
If .ShowDialog() = DialogResult.OK Then
If System.IO.File.Exists(.FileName) Then
MsgBox(.FileName + vbCrLf + "文件存在", Title:="哆哆提示")
yhdfile = .FileName
xlapp.ActiveCell.Value = yhdfile
End If
End If
End With
yhdfile = xlapp.ActiveCell.Value
'xlapp.Workbooks.Open(yhdfile)
End Sub
'新建工作表
Private Sub Button3_Click(sender As Object, e As RibbonControlEventArgs) Handles Button3.Click
For Each s As Excel.Worksheet In xlapp.Worksheets
If s.Name = "dd1" Or s.Name = "dd2" Or s.Name = "dd3" Then
MsgBox(s.Name + "存在")
s.Delete()
End If
Next
'三种方法创建工作表
Globals.ThisAddIn.Application.Worksheets.Add.name = "dd1"
xlapp.Worksheets.Add.name = "dd2"
With xlapp.Worksheets("dd2")
.cells(1, 1) = "哆哆新建工作表dd2"
End With
Dim yhdsht As Excel.Worksheet
yhdsht = xlapp.Worksheets.Add()
yhdsht.Name = "dd3"
End Sub
'复制工作表
Private Sub Button4_Click(sender As Object, e As RibbonControlEventArgs) Handles Button4.Click
Dim Acsht As Excel.Worksheet = xlapp.ActiveSheet
Dim Tosht As Excel.Worksheet
Acsht.Copy(After:=xlapp.Worksheets(xlapp.Worksheets.Count))
Dim shtname As String = "dd" + xlapp.Worksheets.Count.ToString()
xlapp.Worksheets(xlapp.Worksheets.Count).Name = shtname
Tosht = xlapp.Worksheets(xlapp.Worksheets.Count)
MsgBox("工作表名:" + Tosht.Name)
Tosht.Name = "修改dd" + xlapp.Worksheets.Count.ToString()
End Sub
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有