Excel 巨集導資料

2022-03-31 11:44:56 字數 1057 閱讀 3117

解決工作過程中,經常性的從excel中匯入資料庫(sql資料庫),建立巨集

一般巨集都是這種樣子的

sub aaa()

end sub

把下列**放入巨集中

dim i, k as integer

dim conpon, groupbugcode as string

dim strsql as variant

dim connctiong as string

dim cn as new adodb.connection

dim isused, userid, orderid as integer

isused = 0

userid = 0

orderid = 0

dim s as integer

dim o as long

'dsn資料庫連線,需要在控制面板--管理工具--odbc中配置,配置為要匯入的目標資料庫

cn.open "dsn=wcj;uid=sa;pwd=sasa"

with sheet1

for k = 2 to 30000

conpon = .cells(k, 1)'1為列數,列數從1開始計數

if conpon <> "" then

groupbugcode = .cells(k, 2)

strsql = " insert into gb_coupons(coupon,groupbuycode,isused,userid ,orderid,updatedate) values('" & conpon & "','" & groupbugcode & "'," & isused & "," & userid & "," & orderid & ",getdate()) "

cn.execute strsql

s = s + 1

end if

next k

end with

cn.close

set cn = nothing

msgbox "匯入" & s & "條資料成功!"

能實現每分鐘匯入10000條資料

ABAP導資料到Excel總結

abap export data to excel summary 1.doiexport the data to excel description good performance please read the documentfor detail below.excel doi exampl...

Excel巨集教程

excel巨集教程 巨集的介紹與基本使用 1 1 a 6 5 避免迴圈引用 在上述公式賦值過程中,應避免在公式中引用被賦值的單元格,防止迴圈引用錯誤。6 新增批註 可按如下方法格給單元格新增批註 dim 批註文字 as string 批註文字 批註示例 準備批註文字 activecell.addco...

Excel 巨集與VBA 資料型別

允許使用英文本母 數字 見名知意 英文本母開頭 宣告乙個變數並且賦值 sub 變數 宣告乙個變數用dim,格式就是 dim 變數名 as 資料型別 dim score as integer 給score賦值為100 score 100 彈窗顯示score的值 msgbox score end sub...