使用vb引用变量名路径,提示错误类型不匹配 10
OptionExplicitPublicmypathAsStringPrivateSubCommand1_Click()Dimh%,n%,num%DimxlappAsEx...
Option Explicit
Public mypath As String
Private Sub Command1_Click()
Dim h%, n%, num%
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbooks
Dim xlsheet As Excel.Sheets
Me.CommonDialog1.ShowOpen
mypath = Me.CommonDialog1.FileName
MsgBox mypath
Set xlapp = New Excel.Application '创建EXCEL对象
Set xlbook = xlapp.Workbooks.Open(mypath)
num = InputBox("请输入考场人数:")
num = num + 2
xlapp.Visible = True '设置EXCEL对象可见(或不可见)
Set xlsheet = xlapp.xlbook.Worksheets("考场表")
n = 1
If num Mod 2 = 0 Then
For h = num To 1000 Step num
Cells(h, 1).EntireRow.Select
ActiveSheet.Rows(Selection.Row).Insert
ActiveSheet.Rows(Selection.Row).Insert
Cells(h, 1) = "第" & n & "考场"
Cells(h + 1, 1) = "第" & n & "考场"
n = n + 1
Next
Else
For h = num To 1000 Step num - 1
Cells(h, 1).EntireRow.Select
ActiveSheet.Rows(Selection.Row).Insert
Cells(h, 1) = "第" & n & "考场"
n = n + 1
Next
End If
xlbook.Close
xlapp.Quit
Set xlapp = Nothing
End Sub 展开
Public mypath As String
Private Sub Command1_Click()
Dim h%, n%, num%
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbooks
Dim xlsheet As Excel.Sheets
Me.CommonDialog1.ShowOpen
mypath = Me.CommonDialog1.FileName
MsgBox mypath
Set xlapp = New Excel.Application '创建EXCEL对象
Set xlbook = xlapp.Workbooks.Open(mypath)
num = InputBox("请输入考场人数:")
num = num + 2
xlapp.Visible = True '设置EXCEL对象可见(或不可见)
Set xlsheet = xlapp.xlbook.Worksheets("考场表")
n = 1
If num Mod 2 = 0 Then
For h = num To 1000 Step num
Cells(h, 1).EntireRow.Select
ActiveSheet.Rows(Selection.Row).Insert
ActiveSheet.Rows(Selection.Row).Insert
Cells(h, 1) = "第" & n & "考场"
Cells(h + 1, 1) = "第" & n & "考场"
n = n + 1
Next
Else
For h = num To 1000 Step num - 1
Cells(h, 1).EntireRow.Select
ActiveSheet.Rows(Selection.Row).Insert
Cells(h, 1) = "第" & n & "考场"
n = n + 1
Next
End If
xlbook.Close
xlapp.Quit
Set xlapp = Nothing
End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询