The following code is a snippet of code used in a macro that we successfully run under Word 97. The purpose of this part of the macro is to take the text from each cell and write it into a text file (which becomes an HTML file eventually). However running this through Word 2002 I get the following error message:
Run-time error 5: Invalid procedure call or argument.
This occurs on the line : If Asc(am$) = 13) then
and the value of am$ for some reason is set to "" instead of the value of the cell.
The script seems to run correctly for the first cell but then the problem occurs when it tries to read the second cell. Any ideas?
Code:
For i = 1 To NoRows
Print #1, "<tr>"
j = 1
For m = 1 To WordBasic.SelInfo(18)
WordBasic.WW7_EditGoTo Destination:="\Cell"
WordBasic.CharLeft 1, 1
am$ = WordBasic.[Selection$]()
If (Asc(am$) = 13) Then
If (Len(am$) < 3) Then
am$ = " "
End If
End If
WordBasic.CharRight 1, 1
WordBasic.CurValues.TableColumnWidth Dlg
SpBr = WordBasic.Val(Dlg.ColumnWidth)
k = 1
SpBr = SpBr - Width___(j)
j = j + 1
While ((Abs(SpBr) > 0.5))
SpBr = SpBr - Width___(j)
k = k + 1
j = j + 1
Wend
If k > 1 Then
DStart$ = "<" + TD$ + " colspan=" + WordBasic.[LTrim$](Str(k))
Else
DStart$ = "<" + TD$
End If
WordBasic.CurValues.FormatParagraph Dlg1
Select Case Dlg1.Alignment
Case 1: DStart$ = DStart$ + " Align=CENTER>"
Case 2: DStart$ = DStart$ + " Align=RIGHT>"
Case 3: DStart$ = DStart$ + " Align=JUSTIFY>"
Case Else: DStart$ = DStart$ + ">"
End Select
If am$ = " " Then
Print #1, DStart$ + " </" + TD$ + ">"
Else
b$ = ""
a$ = am$
For n = 1 To Len(a$)
If Mid(a$, n, 1) = Chr(13) Then
b$ = b$ + "<br>"
Else
b$ = b$ + Mid(a$, n, 1)
End If
Next n
Print #1, DStart$ + b$;
Print #1, "</" + TD$ + ">"
End If
If m < WordBasic.SelInfo(18) Then WordBasic.NextCell
Next m
WordBasic.TableSelectRow
WordBasic.CharRight 1, 0
Print #1, "</tr>"
TD$ = "td"
Next i
Run-time error 5: Invalid procedure call or argument.
This occurs on the line : If Asc(am$) = 13) then
and the value of am$ for some reason is set to "" instead of the value of the cell.
The script seems to run correctly for the first cell but then the problem occurs when it tries to read the second cell. Any ideas?
Code:
For i = 1 To NoRows
Print #1, "<tr>"
j = 1
For m = 1 To WordBasic.SelInfo(18)
WordBasic.WW7_EditGoTo Destination:="\Cell"
WordBasic.CharLeft 1, 1
am$ = WordBasic.[Selection$]()
If (Asc(am$) = 13) Then
If (Len(am$) < 3) Then
am$ = " "
End If
End If
WordBasic.CharRight 1, 1
WordBasic.CurValues.TableColumnWidth Dlg
SpBr = WordBasic.Val(Dlg.ColumnWidth)
k = 1
SpBr = SpBr - Width___(j)
j = j + 1
While ((Abs(SpBr) > 0.5))
SpBr = SpBr - Width___(j)
k = k + 1
j = j + 1
Wend
If k > 1 Then
DStart$ = "<" + TD$ + " colspan=" + WordBasic.[LTrim$](Str(k))
Else
DStart$ = "<" + TD$
End If
WordBasic.CurValues.FormatParagraph Dlg1
Select Case Dlg1.Alignment
Case 1: DStart$ = DStart$ + " Align=CENTER>"
Case 2: DStart$ = DStart$ + " Align=RIGHT>"
Case 3: DStart$ = DStart$ + " Align=JUSTIFY>"
Case Else: DStart$ = DStart$ + ">"
End Select
If am$ = " " Then
Print #1, DStart$ + " </" + TD$ + ">"
Else
b$ = ""
a$ = am$
For n = 1 To Len(a$)
If Mid(a$, n, 1) = Chr(13) Then
b$ = b$ + "<br>"
Else
b$ = b$ + Mid(a$, n, 1)
End If
Next n
Print #1, DStart$ + b$;
Print #1, "</" + TD$ + ">"
End If
If m < WordBasic.SelInfo(18) Then WordBasic.NextCell
Next m
WordBasic.TableSelectRow
WordBasic.CharRight 1, 0
Print #1, "</tr>"
TD$ = "td"
Next i