惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
Project Zero
Project Zero
博客园 - 聂微东
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
F
Fortinet All Blogs
Martin Fowler
Martin Fowler
Jina AI
Jina AI
C
Check Point Blog
博客园_首页
The GitHub Blog
The GitHub Blog
The Hacker News
The Hacker News
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cisco Blogs
人人都是产品经理
人人都是产品经理
V
Visual Studio Blog
A
Arctic Wolf
博客园 - 三生石上(FineUI控件)
P
Privacy International News Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Forbes - Security
Forbes - Security
阮一峰的网络日志
阮一峰的网络日志
Engineering at Meta
Engineering at Meta
T
Troy Hunt's Blog
Microsoft Security Blog
Microsoft Security Blog
Spread Privacy
Spread Privacy
Schneier on Security
Schneier on Security
K
Kaspersky official blog
宝玉的分享
宝玉的分享
Google DeepMind News
Google DeepMind News
V2EX - 技术
V2EX - 技术
Google DeepMind News
Google DeepMind News
AWS News Blog
AWS News Blog
Know Your Adversary
Know Your Adversary
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Y
Y Combinator Blog
大猫的无限游戏
大猫的无限游戏
S
Security Affairs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - Franky
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The Register - Security
The Register - Security
P
Proofpoint News Feed
小众软件
小众软件
S
Securelist
T
Tor Project blog

博客园 - 水如烟(LzmTW)

.NET的变量在代码集中是不安全的 HOW TO:获取硬盘物理序列号(VB.NET) 一个创建快捷方式类 一个简单的CodeAccessPermission生成器 认识一下Attribute HOW TO:端口打印(比较粗糙) 标记法定义和创建数据库(四) 标记法定义和创建数据库 Sql2005数据类型与Framework类型的对应关系 HOW TO:重启程序(WinForm) HOW TO:设置默认打印机 HOW TO:避免“将COM对象与其基础RCW分开后不能再使用该对象”错误 树和自联表(五) 树和自联表(六) 树和自联表(四) 树和自联表(一) 行政区划数据数据库的设计(脚本) 行政区划数据数据库的设计(七) 行政区划数据数据库的设计(六)
HOW TO:控制是否允许用户退出ExcelApplication的Workbook
水如烟(LzmTW) · 2006-12-21 · via 博客园 - 水如烟(LzmTW)

Author:水如烟  

程序中若打开了一个Workbook给用户直接操作,那么,用户有可能将Workbook关闭了甚至退出了整个ExcelApplicatoin。可以通过以下方法防止这种情形(这个问题留意的人较少,故发首页):

Imports Microsoft.Office.Interop
Public Class Form1Private gWorkbookCanClose As Boolean = FalsePrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
Dim ExcelApplication As New Excel.Application
        
Dim Workbook As Excel.Workbook = ExcelApplication.Workbooks.AddAddHandler Workbook.BeforeCloseAddressOf OnWorkbookBeforeClose

        
Dim Worksheet As Excel.Worksheet = CType(Workbook.Sheets.Add, Excel.Worksheet)
        
With CType(Worksheet.Cells(11), Excel.Range)
            .Interior.ColorIndex 
= 40
            .Value 
= "123"
        
End With

        ExcelApplication.Visible 

= True
    
End SubPrivate Sub OnWorkbookBeforeClose(ByRef cancel As Boolean)
        cancel 
= Not gWorkbookCanClose
    
End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        gWorkbookCanClose 
= Not gWorkbookCanClose
    
End SubEnd Class