Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Nov 2001
    Location
    Springfield, Virginia, USA
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem Macro (Asc) (Word 2K (9.0.3821 SR-1))

    Hi All,

    Used the Fill Down macro below since Word2, I believe; and now it @#$!% out in 2000. Problem is with "If Asc(Data_$) <> 13..." check. The only thing VB Help offers is that I'll get a run-time error if the string contains no characters... but it does. Strange thing is it works with the (almost Identical) Fill Across macro.

    Can you tell what's wrong (or where I might find a working Fill macro)


    Much thanks,
    BobM.

    Dim Message1$, Message2$, Message3$, Message4$

    Private Sub InitializeStringConstants()
    Message1$ = "Selection Not In Table"
    Message2$ = " The Selection Is Too Small"
    Message3$ = "It Should Include Cells From At Least Two Rows"
    Message4$ = "This Feature May Not Be Used in the Header/Footer"
    End Sub

    Public Sub MAIN()
    Dim RStart
    Dim CStart
    Dim REnd
    Dim CEnd
    Dim CLast
    Dim NumRow
    Dim NumCol
    Dim ColCount
    Dim Data_$
    Dim RowCount
    Dim Count_
    Message1$ = ""
    Message2$ = ""
    Message3$ = ""
    Message4$ = ""
    InitializeStringConstants
    ' determine starting/ending point of selction
    ' and number of rows/cols
    RStart = WordBasic.SelInfo(13)
    CStart = WordBasic.SelInfo(16)
    REnd = WordBasic.SelInfo(14)
    CEnd = WordBasic.SelInfo(17)
    CLast = WordBasic.SelInfo(18)
    NumRow = (REnd - RStart) + 1
    NumCol = (CEnd - CStart) + 1

    ' if selection goes outside of table - exit
    If (RStart < 0) Or (CStart < 0) Or (REnd < 0) Or (CEnd < 0) Then
    WordBasic.MsgBox Message1$, 16
    GoTo Bye
    End If

    ' if selection is too small to use - exit
    If RStart = REnd Then
    WordBasic.MsgBox Message2$ + Chr(13) + Chr(10) + _
    Message3$, 64
    GoTo Bye
    End If

    If WordBasic.SelInfo(28) = -1 Then
    WordBasic.MsgBox Message4$, 16
    GoTo Bye
    End If

    ' if area to right of table is selected, ignore it
    If CEnd > CLast Then NumCol = NumCol - 1

    ' goto start of selection and set bookmark
    WordBasic.WW7_EditGoTo Destination:="char"
    WordBasic.CharLeft

    For ColCount = 1 To NumCol
    ' copy item to be filled
    WordBasic.WW7_EditGoTo Destination:="cell"
    WordBasic.CharLeft 1, 1
    Data_$ = WordBasic.[Selection$]()
    ' if the cell is not empty, then copy its contents
    If Asc(Data_$) <> 13 Then WordBasic.EditCopy

    ' clear and then fill in column, cell by cell
    For RowCount = 1 To NumRow
    WordBasic.WW7_EditGoTo Destination:="Cell"
    WordBasic.WW6_EditClear
    If (RowCount = 1) And (ColCount = 1) Then WordBasic.EditBookmark Name:="MSFT", Add:=1
    If Asc(Data_$) <> 13 Then WordBasic.EditPaste
    WordBasic.LineDown 1
    Next RowCount

    ' position for next column
    WordBasic.WW7_EditGoTo Destination:="MSFT"
    For Count_ = 1 To ColCount
    WordBasic.NextCell
    Next Count_
    Next ColCount

    ' goto start of selection and remove bookmark
    WordBasic.WW7_EditGoTo Destination:="MSFT"
    WordBasic.EditBookmark Name:="MSFT", Delete:=1

    Bye:
    End Sub

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Problem Macro (Asc) (Word 2K (9.0.3821 SR-1))

    I can generate an invalid procedure call runtime error under the following conditions: first cell (top cell in first column) has a value, but second cell across (top cell in second column) is empty. Here's why:

    <table border=1 cellpadding=5><td>WordBasic.WW7_EditGoTo Destination:="cell"</td><td>This highlights the blank cell</td><td>WordBasic.CharLeft 1, 1</td><td>This is supposed to deselect the end-of-cell marker, but in an empty cell it selects the previous cell</td><td>Data_$ = WordBasic.[Selection$]()</td><td>This returns an empty string when the entire cell is selected</td><td>If Asc(Data_$) <> 13 Then WordBasic.EditCopy</td><td>ASC of an empty string causes a runtime error</td></table>
    If you test Len(Selection.Text) after that first line, you can tell whether you are going to have a problem. If that length is less than or equal to 2, there is no data in the cell.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •