永发信息网

VB里实现将已打开的DOC、PPT复制到指定的文件夹下

答案:2  悬赏:50  手机版
解决时间 2021-02-02 04:24
  • 提问者网友:了了无期
  • 2021-02-01 15:16
我希望在DOC或是PPT文件(这个文件的文件名可能为任意,位置可能是任意目录下)被打开时,自动将这个被打开的文件复制到一个指定的目录下(比如 D:\docppt 文件夹下),而且想用VB来实现
最佳答案
  • 五星知识达人网友:妄饮晩冬酒
  • 2021-02-01 16:34
复制代码到窗体运行,一秒锺会检查一次打开的文Word、PPt,并复制到C盤根目录 ,具体检查间隔请自行修改.

Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
Dim WithEvents MyTimer As VB.Timer

Private Sub Form_Load()
Set MyTimer = Me.Controls.Add("VB.TIMER", "mytimetest")
MyTimer.Interval = 1000
MyTimer.Enabled = True

End Sub

Private Sub MyTimer_Timer()
On Error Resume Next
Set WordObj = GetObject(, "Word.application")
CopyFile WordObj.activedocument.fullname, "C:\" & WordObj.activedocument.Name, 0
Set PowerPointObj = GetObject(, "PowerPoint.application")
CopyFile PowerPointObj.ActivePresentation.fullname, "C:\" & PowerPointObj.ActivePresentation.Name, 0
End Sub
全部回答
  • 1楼网友:渡鹤影
  • 2021-02-01 16:41
復制代碼到窗體運行,一秒鍾會檢查一次打開的文word、ppt,並復制到c盤根目錄 ,具體檢查間隔請自行修改. private declare function copyfile lib "kernel32" alias "copyfilea" (byval lpexistingfilename as string, byval lpnewfilename as string, byval bfailifexists as long) as long dim withevents mytimer as vb.timer private sub form_load() set mytimer = me.controls.add("vb.timer", "mytimetest") mytimer.interval = 1000 mytimer.enabled = true end sub private sub mytimer_timer() on error resume next set wordobj = getobject(, "word.application") copyfile wordobj.activedocument.fullname, "c:\" & wordobj.activedocument.name, 0 set powerpointobj = getobject(, "powerpoint.application") copyfile powerpointobj.activepresentation.fullname, "c:\" & powerpointobj.activepresentation.name, 0 end sub
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯