更改新工作簿的链接

时间:2019-04-02 08:21:13

标签: excel vba

我正在将工作簿另存为带日期的副本。 我是使用此网站上建议的代码(另存为副本)完成的。

现在我在新工作簿中的链接方面遇到错误。有没有办法设置新工作簿上正确的链接(在新工作簿上)以及“另存为副本”方法?

Sub Button15_Click()  
ActiveWorkbook.Save

'https://stackoverflow.com/questions/18899824/how-to-use-vba-saveas-without-closing-calling-workbook
'SaveAsCopy

Dim thisWb As Workbook, wbTemp As Workbook
Dim ws As Worksheet

On Error GoTo Whoa

Application.DisplayAlerts = False

Set thisWb = ThisWorkbook
Set wbTemp = Workbooks.Add

On Error Resume Next
For Each ws In wbTemp.Worksheets
    ws.Delete
Next
On Error GoTo 0

For Each ws In thisWb.Sheets
    ws.Copy After:=wbTemp.Sheets(1)
Next

wbTemp.Sheets(1).Delete
'wbTemp.SaveAs "C:\Users\Me\Desktop\FileName & Format(CStr(Now), dd-mm-yy-hhumm).xlsm", 52  'Save as timestamp
 wbTemp.SaveAs ("C:\Users\Me\Desktop\") & "FileName" & Format(Now, "dd-mm-yy-hhumm") & ".xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

LetsContinue:
Application.DisplayAlerts = True
Exit Sub
Whoa:
MsgBox Err.Description
Resume LetsContinue

End Sub

0 个答案:

没有答案