为何文件名中含有日期就出错? --excelVB codeSet xlApp CreateObject(Excel.Application)Set xlBook
为何文件名中含有日期就出错? --excel
- VB code
Set xlApp = CreateObject("Excel.Application")'Set xlBook = xlApp.Workbooks.AddSet xlBook = xlApp.Workbooks.Add(App.Path & "\ModelParameter\CP699.xls")Set xlSheet = xlBook.Worksheets(1) If PrintSignal = True Then xlSheet.PrintOutElse AddressStr = "CP699" & "(" & PrintLine & ")" & "-(" & Date & ")" xlApp.ActiveWorkbook.SaveAs (App.Path & "\" & AddressStr)End If'xlApp.Visible = TruexlApp.ActiveWorkbook.ClosexlApp.QuitSet xlSheet = NothingSet xlBook = NothingSet xlApp = Nothing1. 如果包含日期就出错,取消 掉日期没有问题(& Date )?
2.会出现 book1.xls,这个是什么原因?
[解决办法]
可能是日期格式的问题,比如 date返回的格式是2010/01/30这种,那么作为文件是不对的
建议格式化下
AddressStr = "CP699" & "(" & PrintLine & ")" & "-(" & Date & ")"
==》
AddressStr = "CP699" & "(" & PrintLine & ")" & "-(" & Format(Date,"YYYY-MM-DD") & ")"
试下看看
[解决办法]
设置断点,观查AddressStr = "CP699" & "(" & PrintLine & ")" & "-(" & Date & ")"执行后,
AddressStr中是否含有做为文件名的非法字符。(比如/\?|等)。
[解决办法]
Format(Date,"YYYY-MM-DD"),因为有些电脑的格式为"YYYY/MM/DD"
[解决办法]
Format(Date,"YYYY-MM-DD"),因为有些电脑的格式为"YYYY/MM/DD"
或者干脆就是
Format(Date,"YYYYMMDD"),
