不打开Excel表格操作其中内容的代码
大家好:
小弟最近想学写一个宏,要实现以下几个功能:
1、宏在EXCEL1中,打开EXCEL1,不打开EXCEL2,把EXCEL1中某单元格的内容粘贴到EXCEL2中;
2、把EXCEL2剪切到另一个文件夹。
请问各位有没有这样的例子?或者类似的代码供小弟参考一下。
谢谢大家!
1
2
3
4
5
6
7
8
Sub Test()
With CreateObject(“ADODB.connection”)
.Open “Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=’Excel 8.0;HDR=NO;’;Data Source=” & ThisWorkbook.Path & “\W.XLS”
.Execute “UPDATE [SHEET1$H5:H5] SET F1='” & [A1] & “‘”
.Close
End With
Name ThisWorkbook.Path & “\W.XLS” As “D:\W.XLS”
End Sub
Sub Test()
With CreateObject(“ADODB.connection”)
.Open “Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=’Excel 8.0;HDR=NO;’;Data Source=” & ThisWorkbook.Path & “\W.XLS”
.Execute “UPDATE [SHEET1$H5:H5] SET F1='” & [A1] & “‘”
.Close
End With
Name ThisWorkbook.Path & “\W.XLS” As “D:\W.XLS”
End Sub