注册 登录
编程论坛 VB6论坛

菜鸟求解EXCEL代码

不言子 发布于 2022-02-09 01:34, 2253 次点击
只有本站会员才能查看附件,请 登录

以下是网页找到的excel切片器跟随滚动条定位代码
求解怎么才能作用于工作簿中的某一个工作表
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    Dim ShF As Shape
    Dim ShM As Shape
    Dim ShN As Shape
    Dim ShO As Shape
    'specify a slicer
    Application.ScreenUpdating = False
    Set ShF = ActiveSheet.Shapes("类别 2")
    Set ShM = ActiveSheet.Shapes("科目 2")
    Set ShN = ActiveSheet.Shapes("部属 1")
    Set ShO = ActiveSheet.Shapes("经办人")
    'change position of the slicer
    With Windows(1).VisibleRange.Cells(1, 1)
        ShF.Top = .Top + 30
        ShF.Left = .Left + 773
        ShM.Top = .Top + 30
        ShM.Left = .Left + 850
        ShN.Top = .Top + 30
        ShN.Left = .Left + 928
        ShO.Top = .Top + 30
        ShO.Left = .Left + 1006
    End With
    Application.ScreenUpdating = True
End Sub
4 回复
#2
约定的童话2022-02-09 07:16
上传附件看下
#3
wen35232022-02-09 11:54
Private Sub Command1_Click()

' Option1(0).Value = True
 Sum单元 = 0
 
Set Newxls_基数 = CreateObject("excel.application")         '创建Excel应用程序并打开之
     Newxls_基数.Workbooks.Open (App.Path & "\项目基本数据.xls")   '打开EXCEL工作簿
   
   For i = 0 To 15
      Newxls_基数.Worksheets(i + 1).Select '选择工作表
      Newxls_基数.Rows("1:5000").Clear        '清除表格内容
   Next i

 Dim MyStr$
 MyStr = "项目名称='" & Str项目名 & "'"

 For i = 0 To 15
  If i = 0 Then SQL = "select * from 田地平整表 where " & MyStr
  If i = 1 Then SQL = "select * from 道路基数表 where " & MyStr
  If i = 2 Then SQL = "select * from 涵表 where " & MyStr
  If i = 3 Then SQL = "select * from 桥基数表 where " & MyStr
  If i = 4 Then SQL = "select * from 水源基数表 where " & MyStr
  If i = 5 Then SQL = "select * from 输水基数表 where " & MyStr
  
  If i = 6 Then SQL = "select * from 泵站基数表 where " & MyStr
  If i = 7 Then SQL = "select * from 岸坡基数表 where " & MyStr
  If i = 8 Then SQL = "select * from 坡面基数表 where " & MyStr
  If i = 9 Then SQL = "select * from 造林基数表 where " & MyStr
  If i = 10 Then SQL = "select * from 其它基数表 where " & MyStr
  
  If i = 11 Then SQL = "select * from 单元序号表 where " & MyStr & " order by 单ID "
  If i = 12 Then SQL = "select * from 分部序号表 where " & MyStr & " order by 分ID "
  If i = 13 Then SQL = "select * from 单位序号表 where " & MyStr & " order by 位ID "
  If i = 14 Then SQL = "select * from 隐蔽序号表 where " & MyStr & " order by 隐ID "
  If i = 15 Then SQL = "select * from 坐标序号表 where " & MyStr & " order by 坐标ID "
  
      Adodc1(i).CommandType = adCmdUnknown
      Adodc1(i).RecordSource = SQL
      Adodc1(i).Refresh
      Set DataGrid1.DataSource = Adodc1(i)
    If Adodc1(i).Recordset.RecordCount > 0 Then OutToExcel单元基础数 DataGrid1, i      '这地方不能有“(”,有则显示出错!!!
Next i

Newxls_基数.Visible = True   '设置EXCEL可见

'  Newxls_基数.Visible = True   '设置EXCEL可见

End Sub
#4
kedian19682022-03-11 15:47
我太菜了 看不懂題目
#5
蝈曲曲2022-03-23 21:35
请问楼主,表格要实现什么功能?我自己经常用VBA解决工作中的问题
1