VSTO杂项拾零(持续更新中……)

   环境: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, 3)
    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 > 25 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

 

转载于:https://www.cnblogs.com/xiehaofeng/p/6936706.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值