VBA excel:使用Workbook_BeforeSave和ActiveWorkbook.SaveAs强制文件名

我正在构build一个放置在专用networking上的共享文件夹中的窗体。 由单个用户使用的“母表”是一个模板,用于在使用电子表格中的信息保存时生成“子表单”。

为了命名我的'子窗体',我使用Workbook_BeforeSave事件。 我收集我需要的信息来命名文件。 然后,我保存为我的文件的名称。 所有的文件都在同一个文件夹中。

我的代码在我的电脑上工作正常(Excel 2016),但出于某种原因,它不适用于所有计算机(我已经注意到Excel 2013上的问题,但不是在2010年)。

我检查是否每个用户都有正确的访问权限,包含文件的文件夹,他们有。 他们不能手动保存为。

这里是我用来保存的代码:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Application.DisplayAlerts = False Application.EnableEvents = False Cancel = True 'Variable definition Dim Contrat As String Dim Projet As String Dim Requisition As String Dim Marque As String Dim RefPeinture As String 'Get variable values Contrat = Feuil1.Range("C3").Value Projet = Feuil1.Range("C4").Value Requisition = Feuil1.Range("F5").Value Marque = Feuil1.Range("F6").Value RefPeinture = Feuil1.Range("C7").Value 'Determining file name NomDeFichier = "F:\Peinture (Inspection)\Année actuelle\" & Contrat & "_" & Projet & "_" & RefPeinture & "_" & Requisition & "_" & Marque & ".xlsm" 'Saving as file name in .xlsm (fileformat = 52) ActiveWorkbook.SaveAs _ Filename:=NomDeFichier, _ FileFormat:=52, _ Password:="", _ WriteResPassword:="", _ ReadOnlyRecommended:=False, _ CreateBackup:=False 'Inserting document proporty for keyword ThisWorkbook.BuiltinDocumentProperties("Keywords").Value = Feuil1.Range("C3").Value Application.EnableEvents = True Application.DisplayAlerts = True 

结束小组

Interesting Posts