VBA方法總結

2022-05-21 09:47:00 字數 2040 閱讀 6308

1.取得日文漢字的讀音的方法(例如強→キョウ)

2.儲存excel檔案時不彈出是否儲存的alter

wb.close(false) 

3.提示訊息不要

4.excel的sheet比例的大小調整

activewindow.zoom = 70

5. 利用excel來開啟文字檔案的方法  

dim jsfilesheet as worksheet

dim jswb as workbook

workbooks.opentext filename:= _

jsfilename, origin:=65001, _

startrow:=1, datatype:=xldelimited, textqualifier:=xldoublequote, _

consecutivedelimiter:=false, tab:=true, semicolon:=false, comma:=false _

, space:=false, other:=false, trailingminusnumbers:=true

set jswb = activeworkbook

set jsfilesheet = jswb.sheets(jsfunname)

6. 在excel中查詢字元的位置 

dim rngstart

set rngstart = jsfilesheet.cells.find(keyword)

dim addr

addr = rngstart.address

do

set rngstart = jsfilesheet.cells.findnext(rngstart)

loop until addr = rngstart.address

7. 刪除指定的檔案的方法

sub deletefiles(filename as string)

dim fs as object

set fs = createobject("scripting.filesystemobject")

fs.deletefile filename

end sub

8. 刪除指定資料夾裡面的所有檔案,不包括資料夾

sub deletefiles(path as string)

dim fs as object

set fs = createobject("scripting.filesystemobject")

fs.deletefile path & "*.*"

end sub

9. 拷貝檔案之後重新命名

function creatfile(template as string,path as string, beforefilename as string, afterfilename as string)

on error goto lab1

dim fso as object

set fso = createobject("scripting.filesystemobject")

fso.copyfile template, path

name beforefilename as afterfilename

set fso = nothing

creatfile = true

exit function

lab1:

creatfile = false

end function

10. 檔案存在check

function isfileexists(byval strfilename as string) as boolean

if dir(strfilename, 16) <> empty then

isfileexists = true

else

isfileexists = false

end if

end function

VBA 選定sheet方法總結

假定excel共有2個sheet,分別是sis sheet1,而實際後台名稱是sheet2 sheet1,如下圖 同sheets 2 select,指由左至右第2個sheets,即sheet1,包含隱藏sheet!2 worksheets sheet1 select 同sheets sheet1 s...

VBA中操作Excel常用方法總結

要用vba來關閉工作簿,用workbook.close 方法即可,而要退出excel,則用application.quit 方法。下面是一些 示例 關閉活動工作簿,如果工作簿有更改,提示是否儲存 複製 如下 sub closeworkbook activeworkbook.close end sub...

VBA個人總結

sub 合併當前工作簿下的所有工作表 for j 1 to sheets.count if sheets j name activesheet.name then x range a65536 end xlup row 1 sheets j usedrange.copy cells x,1 end ...