找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 2160|回复: 3

[求助] 批量替换对应文本,如何加入功能“完全匹配”、“指定图层” 大家都来帮帮忙吧

[复制链接]
发表于 2014-8-19 09:15:16 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
  1. '打开文件
  2.   Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  3. Private Const SW_SHOW = 5
  4. '-------------------切换线程-------------
  5. Private Declare Function GetWindowThreadProcessId Lib "user32" _
  6.     (ByVal hwnd As Long, lpdwProcessId As Long) As Long
  7. Private Declare Function AttachThreadInput Lib "user32" _
  8.     (ByVal idAttach As Long, ByVal idAttachTo As Long, ByVal fAttach As Long) As Long
  9. Private Declare Function GetForegroundWindow Lib "user32" () As Long
  10. Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
  11. Private Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long
  12. Private Declare Function ShowWindow Lib "user32" _
  13.     (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

  14. 'Private Const SW_SHOW = 5  '与打开文件里面的重复了,这里取消
  15. Private Const SW_RESTORE = 9
  16. '-------------------切换线程-------------
  17. Sub 批量替换()
  18. Dim i As Integer

  19. On Error Resume Next

  20.   FileCopy ThisDrawing.Path & "\PiLiangTiHuan.dll", "C:\WINDOWS\system32\PiLiangTiHuan.dll"
  21.   Shell "regsvr32   /s   PiLiangTiHuan.dll"
  22.   
  23.    Err.Clear
  24.    
  25.    Dim xlApp As Object, xlSheet As Object
  26.    
  27.    
  28.    Set xlApp = GetObject(, "Excel.Application")
  29.    
  30.    If Err Then
  31.      Err.Clear
  32.     Set xlApp = GetObject(, "ET.Application")
  33.          
  34.      End If
  35.   
  36.     If Err Then
  37.        Err.Clear
  38.      
  39.       ShellExecute Me.hwnd, "open", ThisDrawing.Path & "\TT_AutoCAD文字自动替代.xls", vbNullString, vbNullString, SW_SHOW
  40.       GoTo QueDingSheet
  41.    
  42.     End If
  43.    
  44.     If xlApp.Workbooks.Count > 0 Then
  45.     For i = 1 To xlApp.Workbooks.Count
  46.         
  47.         
  48.         If InStr(xlApp.Workbooks(i).Name, "TT_AutoCAD文字自动替代") > 0 Then
  49.           Set xlSheet = xlApp.Workbooks(i).ActiveSheet
  50.           GoTo QueDingSheet
  51.          
  52.         End If
  53.      Next
  54.    
  55.     End If
  56.    
  57.     Err.Clear
  58.      
  59.     ShellExecute Me.hwnd, "open", ThisDrawing.Path & "\TT_AutoCAD文字自动替代.xls", vbNullString, vbNullString, SW_SHOW
  60.    
  61.      
  62. QueDingSheet:
  63.    
  64.    
  65.    
  66.     ForceForegroundWindow Application.hwnd
  67.    
  68.    Dim objForm As Object      ' New PiLiangTiHuan.TiHuan
  69.    
  70.    Set objForm = CreateObject("PiLiangTiHuan.TiHuan")
  71.     Set objForm.Application = Application
  72.    
  73.     DoEvents
  74.    
  75.     objForm.ShowFormMain
  76.    
  77.   Err.Clear
  78.   

  79. End Sub

  80. Private Sub AcadDocument_Activate()
  81.   On Error Resume Next
  82. FileCopy ThisDrawing.Path & "\PiLiangTiHuan.dll", "C:\WINDOWS\system32\PiLiangTiHuan.dll"
  83.   Shell "regsvr32   /s   PiLiangTiHuan.dll"
  84.   
  85.    Err.Clear

  86.   批量替换
  87. End Sub
  88. Public Function ForceForegroundWindow(ByVal hwnd As Long) As Boolean
  89.    Dim ThreadID1 As Long    ' 线程ID
  90.    Dim ThreadID2 As Long    ' 线程ID
  91.    Dim nRet As Long
  92.    
  93.    ' 如果指定的窗体已经在前台,不做任何操作
  94.    If hwnd = GetForegroundWindow() Then
  95.       ForceForegroundWindow = True
  96.    Else
  97.       ' 首先获得指定窗体相关的线程和当前前台窗口所在的线程
  98.       ThreadID1 = GetWindowThreadProcessId(GetForegroundWindow, ByVal 0&)
  99.       ThreadID2 = GetWindowThreadProcessId(hwnd, ByVal 0&)
  100.       
  101.       ' 通过共享输入状态,两个线程分享当前窗口
  102.       If ThreadID1 <> ThreadID2 Then
  103.          Call AttachThreadInput(ThreadID1, ThreadID2, True)
  104.          nRet = SetForegroundWindow(hwnd)
  105.          Call AttachThreadInput(ThreadID1, ThreadID2, False)
  106.       Else
  107.          nRet = SetForegroundWindow(hwnd)
  108.       End If
  109.       
  110.       ' 恢复和重画
  111.       If IsIconic(hwnd) Then
  112.          Call ShowWindow(hwnd, SW_RESTORE)
  113.       Else
  114.          Call ShowWindow(hwnd, SW_SHOW)
  115.       End If
  116.       
  117.       ' 精确地返回函数执行结果
  118.       ForceForegroundWindow = CBool(nRet)
  119.    End If
  120. End Function




  121. 'Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
  122.   
  123. '  On Error GoTo errhand
  124.   
  125. 'If CommandName = "VBALOAD" Or CommandName = "VBAMAN" Or CommandName = "APPLOAD" Or CommandName = "COMMANDLINE" Then

  126. '   Dim objForm As New PiLiangTiHuan.TiHuan
  127. '   Set objForm.Application = Application
  128. '   objForm.ShowFormMain
  129. 'End If

  130. 'errhand:
  131. 'If Err.Number = 0 Then

  132. ' Else
  133.   
  134.   '  MsgBox Err.Description & Err.Number
  135.    
  136.   '  Err.Clear
  137.    
  138. 'End If



  139. 'End Sub
  140. Private Sub AcadDocument_BeginDoubleClick(ByVal PickPoint As Variant)
  141.   批量替换
  142. End Sub



论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 859个

财富等级: 财运亨通

发表于 2014-8-19 09:33:14 来自手机 | 显示全部楼层

回帖奖励 +1 D豆

高大上程序,牛刀很厉害
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 40个

财富等级: 招财进宝

发表于 2014-8-19 15:25:27 | 显示全部楼层
这是求助,还是分享?

点评

求助 希望加入“完全匹配”和”指定图层“的过滤条件  详情 回复 发表于 2014-8-20 20:11
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-8-20 20:11:00 | 显示全部楼层
newer 发表于 2014-8-19 15:25
这是求助,还是分享?

求助  希望加入“完全匹配”和”指定图层“的过滤条件
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-5-30 00:08 , Processed in 0.265245 second(s), 38 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表