Excel VBA - 用于将代码添加到其他宏或更改ProcName或宏名称的宏

时间:2017-11-30 20:20:03

标签: excel vba excel-vba

我通过自动电子邮件发送不受控制的共享工作簿副本。

我已经在工作簿级别上调用“备份”而不是保存

Public Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.EnableEvents = False
Call backup
Cancel = True
Application.EnableEvents = True
End Sub

我想更改备份,以便检查工作表的文件路径,并且只有在存储在

上时才允许它运行保存代码
\\ttnn114a\vol1\Public\I13A Management Information\

因此两条路径都可以正常工作

\\ttnn114a\vol1\Public\I13A Management Information\Back Up Repairs\
\\ttnn114a\vol1\Public\I13A Management Information\REPAIR PROJECTS VM\

以下是我的宏的副本

Sub backup()
Cancel = True
Application.EnableEvents = False    'Stops the recursive saving
Application.DisplayAlerts = False   'Stops the prompt about overwriting the existing file.
If ActiveWorkbook.Name Like "REPAIR VM.xlsm" Then

original_name = ActiveWorkbook.Name
Workbooks(ActiveWorkbook.Name).SaveAs "\\ttnn114a\vol1\Public\I13A Management Information\Back Up Repairs\" & Format(Now(), " dd.MM.yy - hhmmss ") & Application.UserName & Environ("Username") & ".xlsm"
Workbooks(ActiveWorkbook.Name).SaveAs "\\ttnn114a\vol1\Public\I13A Management Information\REPAIR PROJECTS VM\REPAIR VM working macro.xlsm"

Application.EnableEvents = True
Application.DisplayAlerts = True

Else
MsgBox "SAVING DISABLED: This is an uncontroled version of the Repair VM"
End If
End Sub

我正在努力使用ActiveWorkbook.Path = ////语句,我可以将其用作if语句的一部分。

提前谢谢

0 个答案:

没有答案