vba 个人使用总结笔记

1.获取A列最后一个不为空的单元格,表名.[A65536].End(xl方向).Row

	lastNotEmptyRow = Sheet1.[a65536].End(xlUp).Row

2.获取第一行最后一个不为空的单元格,表名.[A65536].End(xl方向).Column

	lastNotEmptyColumn = Cells(2, 255).End(xlToLeft).Column
3.获取当前日期,当前日期和时刻

	current_date = Date
	current_date_time = Now
4.日期相加,加一天/一月/一年的函数, DateAdd(interval, number, date)

interval 必要。字符串表达式,是所要加上去的时间间隔。
number 必要。数值表达式,是要加上的时间间隔的数目。其数值可以为正数(得到未来的日期),也可以为负数(得到过去的日期)。
date 必要。Variant(Date)
或表示日期的文字,这一日期还加上了时间间隔。
interval参数具有以下设定值:
设置描述
yyyy 年
q 季
m 月
y
    一年的日数
d 日
w 一周的日数

ww 周
h 时
n 分钟
s 秒

dateAddDay= DateAdd("d", 1, today)

dateAddMonth= DateAdd("m", 1, today)

dateAddYear= DateAdd("y", 1, today)

5.vba连接数据库

MySQL连接ODBC字符串connstrMySQL = "Driver={" & driver & "};Server = " & sevIP & ";DB=" & DNS & ";UID=" & username & ";PWD=" & password & ";OPTION= 3 ;"
Oracle连接OLE字符串connstr_Oracle= "Provider = MSDAORA.1;Password=" & password & ";User ID=" & username & ";Data Source=" & DNS & ";Persist Security Info=True"

SQLServer连接OLE字符串connstr_SQLServer = "Provider=sqloledb;DSN=" & DNS & ";UID=" & username & ";PWD=" & password & ";"

扫描二维码关注公众号,回复: 420492 查看本文章

    Dim conn As ADODB.Connection
    Dim rs1 As ADODB.Recordset
    Set conn = New ADODB.Connection
    Dim connstr As String
    Dim connsql_if_c1  As String
    conn.ConnectionString = connstr
        conn.Open
        Set rs1 = conn.Execute(connsql_table)
        rs1.Close
        conn.Close
        Set rs1 = Nothing
6.在excelSheet中找对应编码的INFO信息,用到VLookup(mess_code, Sheet5.Range("A:B"), 2, False)) ,对应Excel中的VLookup公式

Function message_box(ByVal mess_code As String) As String
        If IsError(Application.VLookup(mess_code, Sheet5.Range("A:B"), 2, False)) Then
        message_box = "NOT FOUND Message"
        Else
         message_box = Application.VLookup(mess_code, Sheet5.Range("A:B"), 2, False)
        End If
End Function


猜你喜欢

转载自blog.csdn.net/sinat_35187039/article/details/78781728
vba
今日推荐