MS Word VBA: Looping through opened Windows 
Author Message
 MS Word VBA: Looping through opened Windows

I get a   "sub or function not defined"  error when compiling the
following WIN95 MS Word 97 macro code:

Sub Macro2()
'
' Macro2 Macro
' Macro recorded 05/17/00 by BKNOWLTO
'
    Dim i As Integer
    For i = 1 To 23
    Window(i).Activate
    Selection.MoveDown Unit:=wdLine, Count:=2
    Selection.MoveDown Unit:=wdLine, Count:=3, Extend:=wdExtend
    Selection.Copy
    Windows(24).Activate
    Selection.Paste
    Next
End Sub

Apparently one cannot address a Window using *variable* subscripts like
Window(i).  Hard coding for a particular instance of  i, say 2 (and the
fixed target Windows(24)) cause no problems.  How can I program the
macro to loop through windows 1 through 23?

Any thoughts would be much appreciated.

A VBA newbie,

Bill



Sun, 03 Nov 2002 03:00:00 GMT  
 MS Word VBA: Looping through opened Windows
Hi Bill,

It's just a typo, use:

Window(i).Activate
    instead of
Window(i).Activate

Hope this helps,
regards,
Astrid (Microsoft Word MVP)

For direct access to all Microsoft newsgroups:



Quote:
> I get a   "sub or function not defined"  error when compiling the
> following WIN95 MS Word 97 macro code:

> Sub Macro2()
> '
> ' Macro2 Macro
> ' Macro recorded 05/17/00 by BKNOWLTO
> '
>     Dim i As Integer
>     For i = 1 To 23
>     Window(i).Activate
>     Selection.MoveDown Unit:=wdLine, Count:=2
>     Selection.MoveDown Unit:=wdLine, Count:=3, Extend:=wdExtend
>     Selection.Copy
>     Windows(24).Activate
>     Selection.Paste
>     Next
> End Sub

> Apparently one cannot address a Window using *variable* subscripts like
> Window(i).  Hard coding for a particular instance of  i, say 2 (and the
> fixed target Windows(24)) cause no problems.  How can I program the
> macro to loop through windows 1 through 23?

> Any thoughts would be much appreciated.

> A VBA newbie,

> Bill



Sun, 03 Nov 2002 03:00:00 GMT  
 MS Word VBA: Looping through opened Windows
Yah, Astrid, just a typo indeed:

Window(i).Activate
IS the same as
Window(i).Activate
BUT will not work like
Windows(i).Activate

 - Robert.    ;-)


Quote:
> Hi Bill,

> It's just a typo, use:

> Window(i).Activate
>     instead of
> Window(i).Activate

> Hope this helps,
> regards,
> Astrid (Microsoft Word MVP)

> For direct access to all Microsoft newsgroups:



> > I get a   "sub or function not defined"  error when compiling the
> > following WIN95 MS Word 97 macro code:

> > Sub Macro2()
> > '
> > ' Macro2 Macro
> > ' Macro recorded 05/17/00 by BKNOWLTO
> > '
> >     Dim i As Integer
> >     For i = 1 To 23
> >     Window(i).Activate
> >     Selection.MoveDown Unit:=wdLine, Count:=2
> >     Selection.MoveDown Unit:=wdLine, Count:=3, Extend:=wdExtend
> >     Selection.Copy
> >     Windows(24).Activate
> >     Selection.Paste
> >     Next
> > End Sub

> > Apparently one cannot address a Window using *variable* subscripts like
> > Window(i).  Hard coding for a particular instance of  i, say 2 (and the
> > fixed target Windows(24)) cause no problems.  How can I program the
> > macro to loop through windows 1 through 23?

> > Any thoughts would be much appreciated.

> > A VBA newbie,

> > Bill



Sun, 03 Nov 2002 03:00:00 GMT  
 MS Word VBA: Looping through opened Windows
Hi Robert,

Quote:
> Yah, Astrid, just a typo indeed:

> Window(i).Activate
> IS the same as
> Window(i).Activate
> BUT will not work like
> Windows(i).Activate

>  - Robert.    ;-)

Urghhh, I knew it was time to get some sleep ;-)

Regards,
Astrid (Microsoft Word MVP)

For direct access to all Microsoft newsgroups:



Mon, 04 Nov 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. MS Word VBA: Looping through opened Windows

2. MS Word VBA: Looping through opened Windows

3. How to open and read a word doc in a vba loop

4. Elaborated problem on opening UserForm through MS-Word 97 VBA

5. MS PJ 2000 and MS Word via VBA

6. MS Word VBA with MS Graph

7. MS Word VBA with MS Graph

8. How does one look at data in an open MS access aplication from MS Word

9. How does one look at data in an open MS access aplication from MS Word

10. Using VBA Automation to Open Word at the File Open Locatiion

11. Word VBA - Windows to Windows NT compatibility

12. Q:Envoking MS-Word from VB4 when Exchange is using MS-Word

 

 
Powered by phpBB® Forum Software