VBA Code Set

Source: Internet
Author: User

1. Read the local network card address

  DimMymacSetMymac =GetObject("winmgmts:"). InstancesOf ("Win32_NetworkAdapterConfiguration")     for  eachMymacaddressinchMymacIfmymacaddress.ipenabled =True  Then      MsgBox "the MAC address of the native NIC is:"&mymacaddress.macaddressExit  for    End If    Next

2. Reading data from a data set to sheet

    DimStrdate as String, strentity as Stringstrdate=Format(Sheets ("Sheet1"). [B2],"YYYY-MM-DD") strentity= Sheets ("Sheet1"). [B3]DimstrSQL as String        'query statements,strSQL ="SELECT * from xxxx where ..."Sheets ("Sheet1"). Range ("a7:j65535"). ClearContents ' Erase contentDimDs1 asADODB. RecordsetSetDS1 =runSql (strSQL)'get data based on query statements and populate to A7Worksheets ("sheet10"). Range ("A7"). CopyFromRecordset DS1SetDS1 = Nothing      

3. Database connection and execution

Option Explicit PublicConn asADODB. Connection Public Conststrconn ="Provider=SQLOLEDB.1; Persist Security info=true; User Id=sa; Password=ts123;initial Catalog=sqldb;data source=.; Connect timeout=720; " Public FunctionRUNSQL (strSQL) asADODB. RecordsetDimDs asADODB. RecordsetSetDS =NewADODB. Recordset openconn ds. Open strSQL, ConnSetRUNSQL =DS CloseconnEnd Function Public FunctionOpenconn ()IfConn is  Nothing  Then        Setconn =NewADODB. ConnectionEnd If    IfConn. State <>1  ThenConn. Open strconnEnd IfEnd Function

Public FunctionCloseconn ()IfConn. State =1 Then Setconn = Nothing End IfEnd Function

VBA Code Set

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.