以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 用vba删除excel表中指定的行,后在指定的两个单元格分别写入值,出现异常提示…… (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=174086) |
-- 作者:cnsjroom -- 发布时间:2021/12/30 19:43:00 -- 用vba删除excel表中指定的行,后在指定的两个单元格分别写入值,出现异常提示…… 用vba删除excel表中指定的行,后在指定的两个单元格分别写入值,出现异常提示…… 当前代码如下: Dim cm2 As WinForm.ComboBox = e.Form.Controls("ComboBox2") If cm2.Text="" Then MessageBox.Show("请先选择要接收的数据表,然后再进行文件选择.字段匹配.数据导入操作!","温馨提示") Else Dim c4 As WinForm.ComboBox = e.Form.Controls("ComboBox4") If c4.text ="" Then Else Dim b1 As String= "1:" & c4.text With e.Form Dim dlg As New OpenFileDialog dlg.Filter= "Excel 97-2003文件(*.xls)|*.xls|Excel 2007文件(*.xlsx)|*.xlsx" If dlg.ShowDialog = DialogResult.Ok Then Dim App As New MSExcel.Application Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(dlg.FileName) Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1) Dim Rg As MSExcel.Range = Ws.Rows(b1) \'选定多行 Rg.EntireRow.Delete(MSExcel.XlDirection.xlToLeft) \'右面的单元格左移 App.Visible = False If cm2.text="走读式谈话台账" Then Dim Rg1 As MSExcel.Range = Ws.Range(Ws.Cells(1,8)) Rg1.Value = "谈话开始时间" Dim Rg2 As MSExcel.Range = Ws.Range(Ws.Cells(1,9)) Rg2.Value = "谈话结束时间" End If If Wb.WorkSheets(1).name ="sheet1" Then Wb.WorkSheets(1).name = "走读式谈话台账" End If Dim t1 As String =Format(Date.Now,"yyyyMMddhhmmss") Dim dz As String = FileSys.GetParentPath(dlg.FileName) & t1 & FileSys.GetName(dlg.FileName) Wb.SaveAs(dz) wb.close app.quit \'.Controls("TextBox1").value = dz \'.Controls("ComboBox1").Value = "" \'.Controls("Table1").Table.DataTable.DataRows.clear() \'.Controls("ComboBox1").Select() End If End With End If End If 运行出现如下错误: 上述红色代码部分怎么修正呢? |
-- 作者:有点蓝 -- 发布时间:2021/12/30 20:33:00 -- Dim Rg1 As MSExcel.Range = Ws.Cells(1,8) |