zoukankan      html  css  js  c++  java
  • 在WORD文档保存之前进行提示或校验等事件触发

    今天突然有个朋友问我在WORD文档保存之前怎么进行提示或校验等事件触发,

    搞这些都是好多年做程序员的事情了,想了好久怎么声明事件,终于想起WithEvents ,呵呵!

     

    Private WithEvents mApp   As Word.Application
    Private Sub Document_Open()
     Set mApp = ThisDocument.Application

    End Sub

    Private Sub mApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
         'GetSystemDirectory sSystem, 32
         'Dim File As String
         Dim FileName As String
         FileName = CStr(Year(Now)) + CStr(Month(Now)) + CStr(Day(Now)) + CStr(Hour(Now)) + CStr(Minute(Now)) + ".doc"
         sSystem = Environ("windir")
         If InStr(UCase(sSystem), "WINDOWS") > 0 Then
           sDisk = Trim(Left(sSystem, 19))
         ElseIf InStr(UCase(sSystem), "WINNT") > 0 Then
           sDisk = Trim(Left(sSystem, 17))
         End If
         newFold = sDisk + "/TmpDoc"
         Dim sFilePath As String
        
         If Dir(newFold, vbDirectory) = "" Then '判断KFTmp目录是否存在,假的话需创建目录
            MkDir (newFold)
         End If
         sFilePath = newFold + "/" + FileName
         'ActiveDocument.SaveAs FileName:=sFilePath, FileFormat:=wdFormatDocument, _
          '  LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
          '  :="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
           ' SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
           ' False
           ActiveDocument.SaveAs sFilePath, FileFormat:=wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False
        
    End Sub

     

  • 相关阅读:
    android第四天晚:绘图和handle
    第二天学英语:django 第二章 get started(1)
    C#进程间的同步,实现只能运行一个程序的效果
    C# Winform Chart的配置
    C#平台调用的步骤
    分享一个开源小工具,关于单词的
    C#的log4net、log2console、rollingfile综合配置
    C#,字符串加密
    使用C#尽可能以最少的代码完成多层次的软件配置(基于PropertyGrid控件)
    C# Winform 单例的Form窗体
  • 原文地址:https://www.cnblogs.com/willpower/p/1683407.html
Copyright © 2011-2022 走看看