Excel VB Script

Source: Internet
Author: User
Tags strfind
Excel VB getting started private sub calendar#click ()
Range ("A1") = calendar1.value
End sub
Private sub calendar#dblclick ()
Range ("A1") = calendar1.value
Calendar1.visible = false
Range ("A1"). Select
End sub
Private sub worksheet_selectionchange (byval target as range)
If target. Address = "$ A $1" then
Calendar1.value = now ()
Calendar1.visible = true
Else
Calendar1.visible = false
End if
End sub

Bytes ---------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------- Excel Connect_DataBase (SQL Server) 'References Microsoft Activex Data Object 2.0 Library
Private Sub commandbutton#click ()
Dim xlsApp As Object
Dim Cnn As New ADODB. Connection
Dim Rs As ADODB. Recordset


Cnn. ConnectionString = "PROVIDER = SQLOLEDB; SERVER = 192.168.0.0; UID = xxx; PWD = xxx; DATABASE = HR_ST_STPS"
If Cnn. State <> ADODB. ObjectStateEnum. adStateClosed Then Cnn. Close
Cnn. Open

Set Rs = New ADODB. Recordset
With Rs
Set. activeconnection = CNN
. Cursorlocation = aduseclient
. Cursortype = adopenstatic
. Locktype = adlockreadonly
. Open "select * from [hr_st_stps]. [DBO]. [tblporgan]"

End
If Rs. EOF then exit sub
Set xlsapp = Createobject ("Excel. application ")
 
'Ans = msgbox ("Continue ?", Vbyesno)

'Xlsapp. Visible = true
Xlsapp. workbooks. Add
XlsApp. Sheets ("sheet1"). Select
XlsApp. ActiveSheet. Range ("A1"). CopyFromRecordset Rs
If xlsApp. ActiveWorkbook. Saved = False Then
XlsApp. ActiveWorkbook. SaveAs "C: \ Documents and Settings \ hp \ Desktop \ Test.xlsx"
MsgBox ("Save to: C: \ Documents ents and Settings \ hp \ Desktop \ Test.xlsx ")
End If
XlsApp. Quit

Rs. Close
Set Rs = Nothing
Set xlsApp = Nothing

End Sub

Bytes ---------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------- VB automatically selects cell content sub rngfindnext ()
Dim strfind as string
Dim RNG as range
Dim findaddress as string
Strfind = inputbox ("Enter the value to be searched :")
If trim (strfind) <> "" then
With sheet1.range ("B: B ")
Set RNG =. Find (what: = strfind ,_
After: =. cells (. cells. Count ),_
LookIn: = xlValues ,_
LookAt: = xlWhole ,_
SearchOrder: = xlByRows ,_
SearchDirection: = xlNext ,_
MatchCase: = False)
If Not Rng Is Nothing Then
FindAddress = Rng. Address
Do
Rng. Interior. ColorIndex = 6
Set Rng =. FindNext (Rng)
Loop While Not Rng Is Nothing And Rng. Address <> FindAddress
End If
End
End If
End Sub branch --------------------------------------------------------------------------------------------------------------------- Excel Funtion= LOOKUP (100-A10, {0, 10, 20, 30; "A", "B", "C", "D "})

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.