vb+excel2003中另存为excel,“类workbook的saveas方法无效”
DimExcelVersionAsStringDimOsVerSionAsStringDimmyFileNameAsStringDimxlsAppAsObject'定义E...
Dim ExcelVersion As String
Dim OsVerSion As String
Dim myFileName As String
Dim xlsApp As Object '定义EXCEL、ET类
Dim xlsBook As Object '定义工件簿类
Dim xlsSheet As Object '定义工作表类
Set xlsApp = CreateObject("Excel.Application")
ExcelVersion = xlsApp.Version
myFileName = App.Path & "\SaveAs2003(" & ExcelVersion & ").xls"
OsVerSion = xlsApp.OperatingSystem
xlsApp.EnableEvents = False '禁用所有事件
xlsApp.DisplayAlerts = False '提示消息不显示
xlsApp.ScreenUpdating = False '关闭屏幕刷新
Set xlsBook = xlsApp.Workbooks.Open(App.Path & "\Statements.xlt")
Set xlsSheet = xlsBook.Worksheets("Sheet1")
xlsSheet.Activate
xlsSheet.range("B5").Value = 54440.04
xlsSheet.range("A2").Value = 65854.95
If Dir(myFileName) <> "" Then
Kill myFileName
End If
xlsBook.SaveAs myFileName, FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
xlsApp.Quit
xlsApp.EnableEvents = True '禁用所有事件
xlsApp.DisplayAlerts = True '提示消息不显示
xlsApp.ScreenUpdating = True '关闭屏幕刷新
Set xlsSheet = Nothing
Set xlsBook = Nothing
Set xlsApp = Nothing 展开
Dim OsVerSion As String
Dim myFileName As String
Dim xlsApp As Object '定义EXCEL、ET类
Dim xlsBook As Object '定义工件簿类
Dim xlsSheet As Object '定义工作表类
Set xlsApp = CreateObject("Excel.Application")
ExcelVersion = xlsApp.Version
myFileName = App.Path & "\SaveAs2003(" & ExcelVersion & ").xls"
OsVerSion = xlsApp.OperatingSystem
xlsApp.EnableEvents = False '禁用所有事件
xlsApp.DisplayAlerts = False '提示消息不显示
xlsApp.ScreenUpdating = False '关闭屏幕刷新
Set xlsBook = xlsApp.Workbooks.Open(App.Path & "\Statements.xlt")
Set xlsSheet = xlsBook.Worksheets("Sheet1")
xlsSheet.Activate
xlsSheet.range("B5").Value = 54440.04
xlsSheet.range("A2").Value = 65854.95
If Dir(myFileName) <> "" Then
Kill myFileName
End If
xlsBook.SaveAs myFileName, FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
xlsApp.Quit
xlsApp.EnableEvents = True '禁用所有事件
xlsApp.DisplayAlerts = True '提示消息不显示
xlsApp.ScreenUpdating = True '关闭屏幕刷新
Set xlsSheet = Nothing
Set xlsBook = Nothing
Set xlsApp = Nothing 展开
1个回答
展开全部
xlsBook.SaveAs myFileName
直接使用就好,后面的那些参数可以省略,都是默认值
另外,请检查myFileName这个字符变量的值,该值必须要符合目录命名的规则要求!!!
另外如果目标目录是服务器所在目录,请确认目标目录的读写权限!
其实本地目录也是一样,目录权限!
还有
If Dir(myFileName) <> "" Then
Kill myFileName
End If
这段也可以删了,另存为会覆盖目标文件,不需要再删除
直接使用就好,后面的那些参数可以省略,都是默认值
另外,请检查myFileName这个字符变量的值,该值必须要符合目录命名的规则要求!!!
另外如果目标目录是服务器所在目录,请确认目标目录的读写权限!
其实本地目录也是一样,目录权限!
还有
If Dir(myFileName) <> "" Then
Kill myFileName
End If
这段也可以删了,另存为会覆盖目标文件,不需要再删除
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询