vba里怎么判断名字为a的工作簿是否已经被打开了,若未打开,我就将工作表b复制到某路径新建的工作簿中,并命名为a,若已经打开,则先关闭保存工作簿a,再执行上面过程。
Sub b()
On Error Resume Next
pth = "D:\我的文档\"
Set wb = Workbooks("a")
If wb Then wb.Close
Set wb = Workbooks.Add
ThisWorkbook.Sheets("b").Copy before:=wb.Sheets(1)
wb.SaveAs pth & "a.xls"
wb.Close
End Sub追问
On Error Resume Next
pth = "D:\我的文档\"
Set wb = Workbooks("a")
If wb Then wb.Close
Set wb = Workbooks.Add
ThisWorkbook.Sheets("b").Copy before:=wb.Sheets(1)
wb.SaveAs pth & "a.xls"
wb.Close
End Sub追问
大神我又有新的提问了,你有时间帮我去看看啊
温馨提示:答案为网友推荐,仅供参考