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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word 2003 Object Variable or With Block variable not set

Status
Not open for further replies.

JudyL

Instructor
Feb 21, 2001
148
US
I have a macro that copies text from one document to another. The macro is started from the document from which I am trying to copy text. I am getting an error when the macro tries to return to a specific document window that is open while copying text from another document window.

It get an Error 91 - Object Variable or With Block variable not set when it lands on

ActiveDocument.ActiveWinodw.Next.Activate

The other odd thing is that it only is happening on one machine.
 


JudyL,

I advise against using ActiveWhatever.

Use Specific objects, by assigning a Document object vairable to each document as you open (ThisDocument is the object where the code resides)

Second, need to see ALL your code.

Skip,

[glasses] When a wee mystic is on the loose..
It's a Small Medium at Large! [tongue]
 
I totally concur with Skip. It is much, much, better to use Document objects. Here is something that may help you started.
Code:
Dim SourceDoc As Document
Dim CopyToDoc As Document

' as you start the macro from the sourcing doc
Set SourceDoc = ActiveDocument

' now set the CopyToDoc
' if that doc is OPEN (but not active)
' and you know the name
Set CopyToDoc = Documents("[i]doc_name[/i]")

' if you want to add a new document to get
' your copied stuff
Set CopyToDoc = Documents.Add
In any case, now you can direct instructions to explicit documents.
Code:
SourceDoc.Paragraphs(2).Range.Copy

With CopyToDoc.Range
   .Collapse Direction:=wdCollapseEnd
   .Paste
End With
Whatever you like.


faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top