Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Equivalent Excel Macro in Word? 3

Status
Not open for further replies.

TedLes

Instructor
Apr 4, 2010
3
CA
I have an Excel macro which I use constantly. It flicks from one open workbook to the next.

=ACTIVATE.NEXT()
=RETURN()

Is there any equivalent to flick between open documents in Word?
 
Isn't clicking the taskbar simple enough? Not being a smarta$$ - just asking a question.

--
JP
 
My version of Word (Office 95 - shame!) doesn't seem to have a taskbar - or am I wrong?
 
(This should really be in forum707.)
This would seem to do the trick.
Code:
Sub Macro1()
If ActiveWindow.Index = Windows.Count Then
    Windows(1).Activate
Else
   Windows(ActiveWindow.Index + 1).Activate
End If
End Sub

Gavin
 
TedLes,

JPaules was speaking of the Windows taskbar, I'm pretty certain. You should have that, so long as you're not using Windows 3.1 or older, best I recall. [wink]
 
Gavona,

Does that look at ONLY Word document windows, or is it looking at any open/active windows? If just any, then I don't think that will work. You'd end up changing to a different program on some occasions, more than likely.
 



Try this
Code:
Sub NextDocument()
    Dim dc As Document, idx As Integer
    
    idx = 1
    For Each dc In Documents
        If dc.Name = ActiveDocument.Name Then
            If idx = Documents.Count Then
                idx = 1
            Else
                idx = idx + 1
            End If
            Documents(idx).Activate
            Exit Sub
        End If
        idx = idx + 1
    Next
End Sub

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
kyv1611: My code works for me - just going through the Word windows.
VBA Help said:
The Windows collection for the Application object contains all the windows in the application
So it would appear that the same code should work as an Excel macro but it doesn't seem to....ActiveWindow.Index is always 1 - for all workbooks...

I am sure Skip's code is reliable and that he understands it better than I understand mine!!

Gavin
 
Well, I'll be. I'd of thought you would have to specify your use of the Application object for it to not just use the Windows one. Then gain, I suppose within VBA, most things DO use the default application object unless told otherwise.

See, I knew I needed a pot, not a cup, of coffee this morning. [wink]
 
kjv: "you would have to specify your use of the Application object for it to not just use the Windows one."

The VBA assumption is always assume the native Application object.

This is why, say you are in Excel, and you delare
Code:
Dim rngWhatever As Range
to work with code intended for Word, like:
Code:
Dim appWord As Word.Application
Dim wrdDoc As Word.Document
Dim rngWhatever As Range
that rngWhatever object will be an EXCEL range object. VBA assumpes (unless other wise specified) the native Application object. Therefore if you are in Excel, you must use (even if you are using early-binding):
Code:
Dim appWord As Word.Application
Dim wrdDoc As Word.Document
Dim rngWhatever As [b]Word[/b].Range
Likewise, if you declare, in Word
Code:
Dim rngYadda As Range
and try to use that in code that is functioning in Excel, it will fail. VBA assumes it is a WORD range object. As in Gavona's code:
Code:
Sub Macro1()
If [i][b]Application[/b][/i].ActiveWindow.Index = [i][b]Application[/b][/i].Windows.Count Then
    [i][b]Application[/b][/i].Windows(1).Activate
Else
   [i][b]Application[/b][/i].Windows(ActiveWindow.Index + 1).Activate
End If
End Sub

Gerry
 
I have an Excel macro which I use constantly. It flicks from one open workbook to the next."

What exactly is the intention here? The documents are in the Documents collection and are easily accessible via code, as Skip's code demonstrates. But they are also easily accessible from the Window menu. Click Window and you can select from any open document.

Which is why I ask, what is the intention here?

Gerry
 
Interesting thread!

Firstly, I must second Gerry's question as to what exactly the requirement is here, and wonder in what way the use of the Window Menu, or Ctrl+F6 (and/or Ctrl+Shift+F6), does not meet it.

Secondly, I must point out that, although it had a (WordBasic) Macro facility, Word 95 did not have VBA and, so, most of the discussion here is, at best, moot.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Darn, I had a Tony moment and missed that the Office version was 95. Uh, yeah, no VBA. So, I have to also wonder about:
Code:
=ACTIVATE.NEXT()
=RETURN()
besides being Basic (rather than VBA)...what exactly is EQUAL TO those things???????

I will reiterate the question about intention. I have to wonder about "flicking" between...well...anything.

Gerry
 
If it is Office 95 then the only programmability available is WordBasic which doesn't have any features for such things. The parser is really dodgy and almost anything can give you error 100, even stuff that is syntactically correct. Wouldn't recommend doing anything in it.
 
Oh I don't know if I would go that far. WordBasic had some issues, true, but when it was the only game in town I got it to function reasonably well.

Gerry
 
To fumei (TechnicalUser)
6 Apr 10 13:03
"I have an Excel macro which I use constantly. It flicks from one open workbook to the next."

What exactly is the intention here? The documents are in the Documents collection and are easily accessible via code, as Skip's code demonstrates. But they are also easily accessible from the Window menu. Click Window and you can select from any open document.

Which is why I ask, what is the intention here?

The intention is purely convenience - ie. scrolling between open documents by just clicking on the toolbar rather than having to enter "Window" and then select the open document
 
Even in Word 95, you can add commands to toolbars and menus:

Tools > Customize > Toolbars tab
Scroll down the Categories list and select "All Commands"
Scroll down the Commands list (that appears on the right) and select "NextWindow"
Click and drag it to your toolbar of choice
Select an icon from the popup dialog and click "Assign"
Click on "Close" on the Customize dialog, and you're done

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Exactly, there are multiple ways to make navigation between open documents easier. But also, how many documents will you have open? 50? 200? If it is -say - three - I fail to see that it is much of an issue. Let's see:

Your way:

The intention is purely convenience - ie. scrolling between open documents by just clicking on the toolbar rather than having to enter "Window" and then select the open document

What do you have to do - assuming you mean taskbar, rather than toolbar - or even toolbar?
1. Lift up your hand, put it on the mouse
2. move the cursor to the taskbar (toolbar) and click
3. click the document you want.


Built-in native functionality

1. Alt-w
2. select a number

You do not even have to USE the mouse; you can switch betwen ANY document with Alt-w and x - the number of the document listed. That is, you can be typing and switch to a differnt document without ever having to lift your hand to the mouse.

Or put a "Next" icon on your toolbar, as Tony suggests.

Mind you, this is still not "flicking".

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top