查看: 1631|回复: 11
|
Excel (Unhandled win32 exception)
[复制链接]
|
|
我有以下的data,
Part Date
ABC 02.07.2007
ABC 30.07.2007
我要把这"Date"换去date format,要是我直接从File -> Replace,Find ".",Replace "-",那么我就可以拿到以下的日期,这是正确的。
Part Date
ABC 02-07-2007
ABC 30-07-2007
要是我用VBA来写,
Selection.Replace What:=".", Replacement:="-", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
它的result却是这样的,
Part Date
ABC 07-02-2007
ABC 30-07-2007
它把月和日调换了,有没有什么建议把"."的日期换去"-"的date format?
[ 本帖最后由 shinelynn 于 11-9-2007 01:22 PM 编辑 ] |
|
|
|
|
|
|
|
发表于 13-6-2007 10:36 PM
|
显示全部楼层
真想不通???
感觉上两种结果都不可能出现。。。
通常,电脑用的locale是us的。。。日期是mm/dd/yyyy的格式。。。
因此,我们打31/12/07和12/31/07的话,第一个不能被接受,excel会把它当成text/string来处理。。。第二个就对,excel会把它当成number来处理。。。
我帮你写了一个macro。。。你试试看。。。
这个macro有个limitation就是不能选择整个column(1 - 65536 rows)。。。
- Sub convert()
- Dim MinRows As Integer, MaxRows As Integer
- Dim MinCols As Integer, MaxCols As Integer
- Dim i As Integer, j As Integer
- Dim MyVal As String
- Dim SelectedCells
- SelectedCells = Selection
- Dim CellRange As Range
- Dim CellRangeAddress As String
- If TypeName(Selection) <> "Range" Then Exit Sub
- Set CellRange = Selection
- CellRangeAddress = CellRange.Address
- If InStr(1, CellRangeAddress, ":") = 0 Then
- MsgBox _
- "Single cell is selected" & vbCrLf & _
- "Not convertion is performed"
- Exit Sub
- End If
- If InStr(1, CellRangeAddress, ",") > 0 Then
- MsgBox _
- "A multiple cell is selected" & vbCrLf & _
- "Not convertion is performed"
- Exit Sub
- End If
- 'If UBound(SelectedCells, 2) > 1 Then
- 'MsgBox "More than 1 rows is selected"
- 'End
- 'End
- MinRows = CellRange.Row
- MinCols = CellRange.Column
- MaxCols = UBound(SelectedCells, 2) + MinCols - 1
- MaxRows = UBound(SelectedCells, 1) + MinRows - 1
- For i = MinRows To MaxRows
- For j = MinCols To MaxCols
- MyVal = Cells(i, j)
- If MyVal <> "" Then
- MyVal = ConvertDate(MyVal)
- If MyVal <> "" Then Cells(i, j) = MyVal
- End If
- Next
- Next
- End Sub
- 'Return null string if invalid date
- Function ConvertDate(val As String) As String
- Dim MyVal
- MyVal = Split(val, ".")
- Dim Mydate As String
- If UBound(MyVal) = 2 Then
- On Error GoTo myerr
- Mydate = DateSerial(MyVal(2), MyVal(1), MyVal(0))
- If IsDate(Mydate) Then ConvertDate = Mydate
- End If
- Exit Function
- myerr:
- If Err.Number = 13 Then MsgBox "Invalid Date"
- End Function
复制代码 |
|
|
|
|
|
|
|

楼主 |
发表于 13-6-2007 11:44 PM
|
显示全部楼层
原帖由 meemee 于 13-6-2007 10:36 PM 发表
真想不通???
感觉上两种结果都不可能出现。。。
通常,电脑用的locale是us的。。。日期是mm/dd/yyyy的格式。。。
因此,我们打31/12/07和12/31/07的话,第一个不能被接受,excel会把它当成text/string来 ...
第一个可以,只要把control panel的short date format换去dd-MM-yyyy就可。
我已经做好了,其实我的目的是要把那date的weeknum找出来,然后display as YYYYWW (200701,200702...),所以我把换去date format的步骤略掉了 (懒得想了 )。
可是必需加多3个column才能做到。。
Columns("D:F").Select
Selection.Insert Shift:=xlToRight
'用mid把日期用date()弄去date,然后直接找它的weeknum。如果weeknum小于10,就加个0在前方(01,02,03... 到12) Range("D2").Select
ActiveCell.FormulaR1C1 ="=IF(WEEKNUM(DATE(MID(RC[-1],7,4),MID(RC[-1],4,2),MID(RC[-1],1,2)),2)<10,""0""&WEEKNUM(DATE(MID(RC[-1],7,4),MID(RC[-1],4,2),MID(RC[-1],1,2)),2),WEEKNUM(DATE(MID(RC[-1],7,4),MID(RC[-1],4,2),MID(RC[-1],1,2)),2))"
'直接拿year
Range("E2").Select
ActiveCell.FormulaR1C1 = "=RIGHT(RC[-2],4)"
'concatenate起来
Range("F2").Select
ActiveCell.FormulaR1C1 = "=RC[-1]&RC[-2]"
我这假日会试试看你写的code,因为我都看不懂。。。可是想学,谢谢你。。。 |
|
|
|
|
|
|
|

楼主 |
发表于 4-7-2007 09:49 AM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 8-7-2007 01:49 PM
|
显示全部楼层
没有看到coding无法确定那里有问题。。。只能猜测。。。
如果我没猜错,scale qty那排column是有formula的??
在excel里出现 #NUM! 的时候,formula的parameter有问题。。。
formula里的value是number,但是它的value不被接受。。。
例如:logarithm base 0和negetive base是不可能的。。。
所以,在excel输入
=log(1000,0)
=log(1000,-1)
就会出现 #NUM!
如果是invalid value的话。。。像在formula里输入text的话,它会出现 #VALUE!
如果,scale qty那排column没有formula的话。。。很有可能是localize的问题。。。从你捉的图看到你的number format是有separator。。。1,000 和 3,000
你可以试试从control panel那里下手。。。
还有就是,尽量不要在control panel作customize format。。。
就像楼上的date问题。。。用户的date format应该是mm/dd/yyyy的。。。
虽然我们在自己的电脑改成dd/mm/yyyy的format,但我们可不能叫用户自己去改吧?? |
|
|
|
|
|
|
|

楼主 |
发表于 9-7-2007 10:44 AM
|
显示全部楼层
回复 #5 meemee 的帖子
那个column是没有formula的,也没有用任何的coding,这文件是直接从系统export出来的,然后要把这excel放进ms access,因为要用到query。假如是separator的问题,其实我的电脑和用户的电脑都是有separator的,可是出来的结果都不一样。还有别的可能性吗?
我。。没叫用户自己去改format,是我去他们的位帮他们该。。 知道不该这么做,可是都不知道要怎么解决,所以只好偷工减料。。 |
|
|
|
|
|
|
|
发表于 14-7-2007 08:54 PM
|
显示全部楼层
别的可能性??
看看ms的解释。。。
Some fields are blank or display a string, such as #NUM. Access encountered a value that is not compatible with the data type it assigned the field. By default, Access scans the first eight rows to guess the data type of the column. If Access encounters values beyond the eightth row that are not compatible with the chosen data type, it will simply ignore those values and not import (or link to) them. If you think Microsoft Access assigned the correct data type for this field, edit your text file or spreadsheet to correct errors, and then import again. Otherwise, import again and specify the appropriate data type.
这里还有类似的解释:
http://www.accessmonster.com/Uwe/Forum.aspx/access/77689/NUM-error-on-linked-table |
|
|
|
|
|
|
|

楼主 |
发表于 13-8-2007 03:31 PM
|
显示全部楼层
回复 #7 meemee 的帖子
谢谢。。我想着用公司的一个BI tool 帮他们解决,我的用户直接写电邮向全世界的人说我的program不能用。。
还有另一个问题。我counter part做了一个macro,我run时它就出现这个error,
"Method 'FaceID' of object '_CommandBarButton' failed"
然后我又看不到它的coding,不给我debug,这是么东东来的? 该怎么做? |
|
|
|
|
|
|
|

楼主 |
发表于 11-9-2007 03:40 PM
|
显示全部楼层
之前的face id已经解决,Excel 2000不能support CommandBarButton 的face id
有谁碰过这问题吗? 一个用户寄个excel文件给我,我可以开得到,可是save不到,一save,这error就跑出来了。
 |
|
|
|
|
|
|
|
发表于 17-9-2007 04:53 PM
|
显示全部楼层
很可能里面有段 MACRO 出错,尝试把 MACRO 关掉再试试看。 |
|
|
|
|
|
|
|

楼主 |
发表于 19-9-2007 04:11 PM
|
显示全部楼层
这excel文件里没macro,纯报告而已。我已暂时叫用户把里头的资料copy去新的excel文件,可是我还是找不到问题根源。 |
|
|
|
|
|
|
|

楼主 |
发表于 19-9-2007 04:19 PM
|
显示全部楼层
我试debug,也不行,进了ms studio之后有另一个error msg,
 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|