我在excel VBA中有一个代码,它保存了一个带有编码路径和文件名的工作簿,该工作簿在我家运行Windows 8和Office 2013的计算机上完美运行。 当我尝试在运行Windows XP和Office 2003的工作计算机上使用它时,它会忽略编码的路径和文件名,并打开另存为对话框,默认为My Documents目录。
目的是让工作中的用户单击“保存”,文件将自动转到具有个性化文件名的网络驱动器。他们不应该选择路径或文件名。
我一直在测试路径C:\Temp\
并保存一个普通的.XLS文件,该文件应该适用于两个版本的Excel。
我在没有禁用警报的情况下尝试了它,它没有提供有关它忽略路径和文件名的原因的线索。我也试过fileformat:=xlnormal
等没有运气。
为什么会发生这种情况,我该如何解决?
以下是代码:
Sub FeedBackSave()
' Save the Feedback worksheet created by the user to the network drive using the path copied from
' the Management workhseet cell A11, the resource name copied from cell A1 and todays date as the filename.
Dim wsh As Worksheet
Dim nme, pth, TodaysDate As String
TodaysDate = format(Now, "dd-mm-yy")
nme = Range("A1").Value
pth = Worksheets("Management").Range("A11").Value
Application.ScreenUpdating = False
Application.DisplayAlerts = False ' Prevents alerts like incorrect file type or overwrite file y/n to permit 1 click save
'Save Feedback worksheet
ActiveWorkbook.Close SaveChanges:=True, Filename:=pth & "FeedBack " & nme & " " & TodaysDate & ".xls"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:0)
Saveas关闭工作簿之前,可能会有帮助。,检查范围,不确定它们是否在同一张纸上。
Sub FeedBackSave()
' Save the Feedback worksheet created by the user to the network drive using the path copied from
' the Management workhseet cell A11, the resource name copied from cell A1 and todays date as the filename.
Dim wsh As Worksheet
Dim nme As String, pth As String, TodaysDate As String, FName As String
Set ws = Worksheets("Management")
TodaysDate = Format(Now, "dd-mm-yy")
nme = Range("A1").Value
pth = ws.Range("A11").Value
FName = pth & nme & "-" & TodaysDate & ".xls"
Application.DisplayAlerts = 0
With ActiveWorkbook
.SaveAs FileName:=FName
.Close
End With
End Sub