Set originalWb = Workbooks.Open(originalFileStr)
如果文件是带用户名和密码时,可以使用如下函数。
Set originalWb = Workbooks.Open(originalFileStr, 0, True, "用户名", "密码")
targetWb.Save
targetWb.Close
如果关闭前没有报错,Excel 会提示要不要保存。如果你的流程既不想保存又不想弹出提示。可以用下面这段代码关闭。
targetWb.Close SaveChanges = False
templetFile = ThisWorkbook.Path & "\员工奖惩自动化处理-模板.xlsx"
Application.DisplayAlerts = False
Application.ScreenUpdating = False
For i = 1 To Workbooks.Count If Workbooks(i).Name = cFile Then MsgBox ("不能同时打开两个同名的文件,请检查并修改文件名!") Exit Function End If Next i
v_has_open = False For i = 1 To Workbooks.Count If Workbooks(i).FullName = targetFile Then Set originalWb = Workbooks(i) v_has_open = True End If Next i If v_has_open = False Then Set originalWb = Workbooks.Open(targetFile) End If originalWb.Activate