macros using 2 open documents.

M

Miskacee

The 'otherDoc" will be opened first. No matter if the macro gets to otherDoc
or FixedDoc.activate, it doesn't recognize either one. Error message says
Object Required.
 
T

Tony Jollans

This is very difficult without seeing more of your code.

The change to your code that I posted before set fixedDoc at the point that
it opened the document - so it must be set but it could have gone out of
scope. Do you have multiple procedures all trying to use it?

If so, move the declaration to the top of the module (before the first sub
or function) to make it global - or, if you haven't explicitly Dimmed it, do
so at th emodule level ..

Dim fixedDoc as word.document
 
M

Miskacee

Here's the code:
Sub copyID()
'
' copyID Macro
' Macro recorded 11/15/2005 by kcaulfield
'
'Copies database ID to column
Dim otherDoc As Word.Document
Dim fixedDoc As Word.Document

Set otherDoc = ActiveDocument

For Each otherDoc In Documents
If Not otherDoc Is fixedDoc Then Exit For
Next
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Database ID:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Copy

'Secondary document (2)
ChangeFileOpenDirectory "C:\Aim compensation\"
Set fixedDoc = Documents.Open(FileName:="""PMP Import.doc""",
ConfirmConversions:=False, _
ReadOnly:=True, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto)
fixedDoc.Activate
Selection.SelectColumn
Selection.Paste

End Sub
----------------I can't get past the code before I get an error about Object
Required.-----
 
T

Tony Jollans

With this version of the code you do not want the lines marked (see below) -
they were only required before I found out you didn't already have the fixed
doc already open.

--
Enjoy,
Tony


Miskacee said:
Here's the code:
Sub copyID()
'
' copyID Macro
' Macro recorded 11/15/2005 by kcaulfield
'
'Copies database ID to column
Dim otherDoc As Word.Document
Dim fixedDoc As Word.Document

Set otherDoc = ActiveDocument

=============== delete these lines below ====================
For Each otherDoc In Documents
If Not otherDoc Is fixedDoc Then Exit For
Next
=============== delete these lines above ====================
 
M

Miskacee

OK, I will remove. However, I have it going right now with that part in it
but need to tweak a section. I'll try removing it and see what happens.
Again, thank you for all of your assistance!
Kate.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top