|
感谢赵老师的答复!
那执行宏按钮复制文件后,如何直接自动打开这个文件呢? 如何修改这段代码
即打开这个文件: arr(m, 1) & ".xlsx"
- Private Sub CommandButton1_Click()
- Dim cnn, arr, m&, f$, SQL$
- If ActiveCell.Value = "" Then Exit Sub
- If ActiveCell.Column = 1 Or ActiveCell.Row < 3 Then Exit Sub
- arr = [a1].CurrentRegion
- m = ActiveCell.Row
- f = ThisWorkbook.Path & "" & arr(m, 1) & ".xlsx"
- If Dir(f) <> "" Then Kill f
- FileCopy ThisWorkbook.Path & "\分类模板.xlsx", f
- Set cnn = CreateObject("ADODB.Connection")
- cnn.Open "Provider=Microsoft.Ace.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=No';Data Source=" & f
- SQL = "update [Sheet1$b1:b1] set f1='" & arr(m, 1) & "'"
- cnn.Execute SQL
- SQL = "update [Sheet1$c2:c2] set f1=" & arr(m, 2)
- cnn.Execute SQL
- SQL = "update [Sheet1$c3:c3] set f1=" & arr(m, 4)
- cnn.Execute SQL
- SQL = "update [Sheet1$c4:c4] set f1=" & arr(m, 6)
- cnn.Execute SQL
- MsgBox "已生成" & arr(m, 1) & ".xlsx"
- cnn.Close
- Set cnn = Nothing
- End Sub
复制代码
补充内容 (2016-3-12 20:10):
求助
补充内容 (2016-3-12 20:10):
求助 |
|