以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  EXCEL VBA 查找替换代码  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=124633)

--  作者:benwong2015
--  发布时间:2018/9/11 9:17:00
--  EXCEL VBA 查找替换代码
如果excel表 123.xls,如何将以下查找56替换成A的VBA转成Foxtable的代码

Sub 宏3()
\'
\' 宏3 宏
    Cells.Replace What:="56", Replacement:="A", LookAt:=xlPart, SearchOrder _
        :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End Sub


--  作者:benwong2015
--  发布时间:2018/9/11 9:51:00
--  
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("c:\\abc.xls")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(2)
Dim Rg As MSExcel.Range
Rg = Ws.Range(Ws.Cells(5,6), Ws.Cells(10,20))
Rg.Value = "abc"
App.Visible = True

或者如何将Rg = Ws.Range(Ws.Cells(5,6), Ws.Cells(10,20))改成表中所有含有“56”的单元格,并且将56替换成A

--  作者:有点甜
--  发布时间:2018/9/11 9:54:00
--  
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("D:\\test.xls")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim Rg As MSExcel.Range = Ws.UsedRange
rg.Replace(What:="56", Replacement:="A", LookAt:=2, SearchOrder _
        :=1, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False)
app.visible = True