环境:win 7+visual basic 2008 侧重:VSTO 界面:sheetbook工作簿
1.创建一个过程并调用(2017.6.3)
Public Class Sheet1
Private Sub Fileprocessor(ByVal fileName As String)
Dim fs As System.IO.FileStream = New System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)
fs.Close()
End Sub Private Sub Sheet1_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
Fileprocessor("c:\download\csvdata.txt")
End Sub Private Sub Sheet1_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown End Sub End Class
2.读取TXT文件并显示在sheet1的单元格中(2017.6.3)
Public Class Sheet1 Private Sub Sheet1_Startup1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
Application.ScreenUpdating = False
Application.Workbooks.Open("C:\download\csvdata.txt", Delimiter:=",", Editable:=True, AddToMru:=True)
Application.ScreenUpdating = True
End Sub
Private Sub sheet1_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown End Sub
End Class
3.读取网络地址中的TXT文件并显示在单元格中(2017.6.3)
Public Class Sheet1 Private Sub Sheet1_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
Me.Application.Workbooks.OpenText("http://Download/CSVData.txt", Excel.XlPlatform.xlMacintosh, )
End Sub
Private Sub sheet1_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown End Sub
End Class
4.加载杂项数据(2017.6.3)
Public Class Sheet1 Private Sub Sheet1_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
With Me.QueryTables.Add(Connection:="URL;http://edition.cnn.com/travel/", Destination:=Range("a1"))
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh(BackgroundQuery:=False)
.SaveData = False
End With
End Sub
Private Sub sheet1_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown End Sub
End Class
5.加载XML文件数据
Public Class Sheet1 Private Sub Sheet1_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
Me.Application.Workbooks.OpenXML("C:\Download\Test.xml")
End Sub
Private Sub sheet1_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown End Sub
End Class
6.Outlook发送的人数超过25个时,以对话框的形式提示。
Imports Outlook = Microsoft.Office.Interop.Outlook
Public Class ThisAddIn Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup End Sub Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown End Sub Private Sub Application_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean) Handles Application.ItemSend
Dim myItem As Outlook.MailItem
If TypeOf Item Is Outlook.MailItem Then
myItem = CType(Item, Outlook.MailItem)
For Each recip As Outlook.Recipient In myItem.Recipients
If recip.AddressEntry.Members.Count > Then
'询问用户是否真的要发送这个E-mail
Dim message As String
message = "send mail to {0} with {1} people?"
Dim caption As String = "More than 25 recipients"
Dim buttons As MsgBoxStyle
buttons = MsgBoxStyle.YesNo
Dim result As MsgBoxResult
result = MsgBox(String.Format(message, recip.AddressEntry.Name, recip.AddressEntry.Members.Count), caption, buttons)
If result = MsgBoxResult.Ok Then
Cancel = True
Exit For
End If
End If
Next
End If
End Sub
End Class