Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

Stump on .range.characters

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Aaron - 07 Oct 2004 17:11 GMT
Hello,

I have been writing code to format proposals that are
exported from a program.  So far so good for formatting,
borders etc.  Thank you again to Helmut.

Here is the code:

Sub TestLeng()

Dim SignLen, SignCenter, SignPaste As Integer

With ActiveWindow ' word bug workaround
  .View = wdPrintView
  .View = wdNormalView
  .View = wdPrintView
End With

SignLen = 0
With Selection
 If .Range.Characters(30) = .Text Like "[A-z,0-9]" Then
   .Range.Characters(30).Select
     While .Text Like "[A-z,0-9]"
       .MoveRight Unit:=wdCharacter, Count:=1
       SignLen = SignLen + 1
       MsgBox ("its like it")
     Wend
     MsgBox (SignLen)
     .MoveLeft Unit:=wdCharacter, Count:=SignLen,
Extend:=wdExtend
 End If
End With
End Sub

the .moveleft is all on one line.  What happens is when
it hits a .Range.Characters(30).Select it errors saying
that the requested member of the collection does not
exist.  I use that line of code in several macros and it
works fine, however it does not seem to work here.  The
line is greater than 30 chars (it is 106 orig so I tried
to trim it down to one line aka < 92.  I thought it may
be because it is on page 5, that was not it.

Why is it just this code that has the error and how do I
correct it?

Thank you,

Aaron
Aaron - 07 Oct 2004 17:54 GMT
The reason why it worked in other code is because it was
selected first with .Bookmarks("\line").Select to make it
a selection.

As not to waste a good one person string does anyone know
how to go direct to a character without using the
bookmark/line?

Cheers,

Aaron

>-----Original Message-----
>Hello,
[quoted text clipped - 47 lines]
>Aaron
>.
Jezebel - 08 Oct 2004 00:35 GMT
First, for this sort of coding you shouldn't be using the Selection object
at all, other than to determine what the user wants the macro to work on.
Formatting instructions can be applied directly to Range objects: this is
faster, more reliable, simpler to code, and doesn't interfere with the user.
In your loop, you don't need to select the character and extend the
selection to count the number of characters that meet your criterion -- you
can just check the character --

pStart = 30
pSignLen = 0
Do while Selection.Range.Characters(pStart + pSignLen) like "...."
   pSignLen = pSignLen + 1
Loop

Some other issues with your code:

Dim SignLen, SignCenter, SignPaste As Integer

This declares SignLen and SignCenter as variants. Only SignPaste is declared
here as an integer. You need to set the type of each variable individually;
and in this case they should all be declared as Longs. Integers are
available in VBA only for backward compatability. They are MORE work for the
system than longs, because it's a 32 bit operating system.

Like "[A-z,0-9]"   -- I doubt this is really what you intend. This matches
any uppercase letter, any lower case letter, any digit, comma, or any of [
\ ] ^  _ `   (those last being the characters that fall between "Z" and
"a"). I think you actually want "[A-Za-z0-9]"

> The reason why it worked in other code is because it was
> selected first with .Bookmarks("\line").Select to make it
[quoted text clipped - 59 lines]
> >Aaron
> >.
Aaron - 08 Oct 2004 17:48 GMT
Hi Jezebel,

I am looking forward to testing the code you have given
for testing.  Here is the whole code (which is still
stoping on lines, you will see why) is below.  If you
have the time I would like to know how to create arrays
as there is not a type array as there is in Excel VBA and
what appears to be every other programming language out
there.  Finally is there a way to write the spaces
instead of type.text and put in 40 spaces etc.

Thank you,

Aaron

Sub CleanBottomMoney()

Dim iLn1 As Integer ' Line 1 of 2
Dim iLn2 As Integer ' Line 2 of 2
Dim iPg1 As Integer ' Last Page
Dim iStr As Integer ' line to start with
Dim iEnd As Integer ' line to stop at
Dim SignLen, SignCenter, SignPaste As Integer

With ActiveWindow ' word bug workaround
  .View = wdPrintView
  .View = wdNormalView
  .View = wdPrintView
End With

iPg1 = Selection.Information(wdNumberOfPagesInDocument)

MsgBox (iPg1)

Selection.ExtendMode = False
Selection.GoTo What:=wdGoToPage, Count:=iPg1

With Selection
  .Collapse
  .ExtendMode = False
  iLn1 = .Information(wdFirstCharacterLineNumber) 'set
line one advancer
  .MoveDown
  iLn2 = .Information(wdFirstCharacterLineNumber)  ' set
line two advancer
While iLn1 <> iLn2
  .Bookmarks("\line").Select
  If Len(.Range.Text) > 24 Then
     ''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''
     '  Clean the PO area and bring the total to the
correct line      '
     ''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''
      If .Range.Characters(2).Text = "P" _
        And .Range.Characters(3).Text = "." Then
       .Range.Characters(55).Select
          While .Text Like "[A-z,0-9]"
            .MoveRight unit:=wdCharacter, Count:=1
            SignLen = SignLen + 1
          Wend
           MsgBox (SignLen)
            .MoveLeft unit:=wdCharacter, Count:=SignLen,
Extend:=wdExtend
            .Cut
            'Perform the calculations to where it should
be pasted 'on the PO line.
               SignCenter = Round(SignLen / 2)
               SignPaste = (13 - SignCenter) + 12
               'Paste the signature and delete excess
line
                 .Bookmarks("\line").Select
                 .Range.Characters(SignPaste).Select
                 .Paste
                 .MoveLeft unit:=wdCharacter,
Count:=SignLen, Extend:=wdExtend
                    If Selection.Font.Underline =
wdUnderlineNone Then
                        Selection.Font.Underline =
wdUnderlineSingle
                    Else
                        Selection.Font.Underline =
wdUnderlineNone
                    End If
                      .MoveRight unit:=wdCharacter,
Count:=1, Extend:=False
                      .Delete unit:=wdCharacter, Count:=
(SignLen - 1)
                      'Delete Excess spaces and bring
total to correct line
                      .MoveRight unit:=wdCharacter,
Count:=18, Extend:=False
                      .Delete unit:=wdCharacter, Count:=
(40 - SignLen)
 
      End If
      '''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''
      '  Take care of Subtotal line and other lines
      '''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''
      If .Range.Characters(24) = "S" Then
        .Range.Characters(24).Select
        .MoveRight Count:=12, Extend:=wdExtend
          If .Range.Text = "SUBTOTAL....:" Then
             MsgBox ("this is it")
             .MoveLeft
             .TypeText
Text:="                                        "
          End If
      Else
          If .Range.Characters(30) = "=" Then
             .Range.Characters(30).Select
             .TypeText
Text:="                                                  
"
          End If
          If .Range.Characters(24) = "D"
And .Range.Characters(25) = "E" _
           And .Range.Characters(26) = "L" Then
             .Range.Characters(24).Select
             .TypeText
Text:="                                       "
          End If
          If Len(.Range.Text) > 78 Then
            If .Range.Characters(79) = "D" Then
               .Range.Characters(80).Select
               .Delete unit:=wdCharacter, Count:=79
            End If
          End If
      End If
  End If

  iLn1 = .Information(wdFirstCharacterLineNumber)
  .MoveDown
  iLn2 = .Information(wdFirstCharacterLineNumber)
Wend
End With

MsgBox ("Have a Nice Day")

End Sub
>-----Original Message-----
>First, for this sort of coding you shouldn't be using the Selection object
[quoted text clipped - 91 lines]
>
>.
Jezebel - 09 Oct 2004 01:18 GMT
Not sure what you're getting at about type arrays. Word VBA, Excel VBA, and
all the other VBAs are (by definition) identical -- it's whatever version of
the "VBA for applications" library is installed on your computer -- Word,
Excel, and all other VBA-enabled applications use this same library for
their basic functions. If you're having problems declaring an array of a
UDT, then there is some other problem with your code; but in any case you
might find it easier to use a collection of class objects.

An alternative to TypeText is to use the various the Range object's Insert
methods. Or you can simply redefine the Range's Text property.

> Hi Jezebel,
>
[quoted text clipped - 260 lines]
> >
> >.
Steve Rindsberg - 04 Nov 2004 19:56 GMT
> I am looking forward to testing the code you have given
> for testing.  Here is the whole code (which is still
[quoted text clipped - 3 lines]
> what appears to be every other programming language out
> there.  

Dim MyArray(1 to 10) as String ' a ten-element array of strings
Dim MyBiggerArray(1 to 10, 1 to 100) as Object ' a 10 by 100 array of objects

> Finally is there a way to write the spaces
> instead of type.text and put in 40 spaces etc.

Debug.Print "There are 20 spaces between here -->" & space(20) & "<-- and here"

> Thank you,
>
[quoted text clipped - 249 lines]
> >
> >.

Signature

--
Steve Rindsberg, PPT MVP
PPT FAQ:  www.pptfaq.com
PPTools:  www.pptools.com

================================================
Apologies for the delayed response.
Just back from PowerPoint Live 2004
Had a great time, learned a lot
================================================

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.