Allora faccio un riepilogo :
File Connect.dsr
File mMain.bas (manca una parte dedicata alla connection aperta in un altro modulo che non metto perchè non ci interessa per la soluzione)codice:Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant) Set mVarExcelApplication = Application
codice:Option Explicit Public mVarExcelApplication As Excel.Application Public Sub Elabora() Dim sSql As String Dim ObjRs As ADODB.Recordset Dim sh As Worksheet Dim trg As Range Dim CountBlank As Double Dim sWhat$, sReplace$ oSql = "select * from tmpCampiReplace" Set ObjRs = New ADODB.Recordset ObjRs.Open oSql, CONN_SQL If ObjRs.bof then 'do nothing else Do Until ObjRs.EOF sWhat = ObjRs("field_text") sReplace = ObjRs("field_replace") If Len(Trim(sReplace)) < 1 Then sReplace = "'" End If On Local Error Resume Next For Each sh In mVarExcelApplication.ActiveWorkbook.Worksheets If sh.Name <> "Protetto" Then On Local Error Resume Next Set trg = sh.Range("A1:IV65536") CountBlank = mVarExcelApplication.WorksheetFunction.CountBlank(trg) If CountBlank < 16777216 Then trg.Replace What:=sWhat, Replacement:=sReplace, LookAt:=2, SearchOrder:=1, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False End If Set trg = Nothing End If Next ObjRs.MoveNext Loop end if ObjRs.Close Set ObjRs = Nothing End Sub

Rispondi quotando