zoukankan      html  css  js  c++  java
  • Excel VB Script

    Excel VB 일력

    Private Sub Calendar1_Click()
    Range("A1") = Calendar1.Value
    End Sub
    Private Sub Calendar1_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
     
     
     ---------------------------------------------------------------------------------------------------------------------
     ---------------------------------------------------------------------------------------------------------------------

    Excel Connect_DataBase(Sql Server)

    '引用Microsoft Activex Data Object 2.0 Library
      Private Sub CommandButton1_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 With
        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 ("保存到: C:\Documents and Settings\hp\Desktop\Test.xlsx")
        End If
        xlsApp.Quit
       
        Rs.Close
        Set Rs = Nothing
        Set xlsApp = Nothing
       
      End Sub
     
     ---------------------------------------------------------------------------------------------------------------------
     ---------------------------------------------------------------------------------------------------------------------

    VB 自动选择Cell 内容

    Sub RngFindNext()
          Dim StrFind As String
          Dim Rng As Range
          Dim FindAddress As String
          StrFind = InputBox("请输入要查找的值:")
          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 With
          End If
    End Sub
     
     
     
     ---------------------------------------------------------------------------------------------------------------------
     
    Excel Funtion
    =LOOKUP(100-A10,{0,10,20,30;"A","B","C","D"})
     
  • 相关阅读:
    消息队列 RPC之间的区别与联系
    RabbitMQ, ZeroMQ, Kafka 是一个层级的东西吗, 相互之间有哪些优缺点?
    嵌入式软件开发工程师谈软件架构的设计
    值得推荐的C/C++框架和库 (真的很强大)
    10.2-嵌入式系统库资源集合
    正则表达式
    vscode代码阅读
    vscode配置
    VSCode的开发环境zsESampleLinux
    MySQL与宿主Linux之间交互式执行命令
  • 原文地址:https://www.cnblogs.com/kevinkim/p/2298913.html
Copyright © 2011-2022 走看看