Home

Macros and Programming

 

CardboxForumsMacros and Programming > "Mail-merge macro fails in Win7"

Mail-merge macro fails in Win7

My Carbox mail-merge run macro fails worked well in WinXP, but fails in Win7

Current user: [none]
Register / Log In · Help

Posted By Post

mermayde

31-Oct-2011 10:52

The mail-merge macro I copied in the past from Cardbox input worked well under WinXP; it 'survived' the transfer from Word 2003 to Word 2007, but fails in Win7. Who knows why?
I use:

Records.WriteToFile cbxWriteFormatCSV+cbxWriteOptionFieldHeading+cbxWriteOptionAlwaysQuote,"E:\3-DataEssentials\Cardbox 3.0\MergeDocs\TOWORD.txt","ORGANISATION,DEPARTMENT,STREET,POSTALCODE,PLACE,COUNTRY,TITLE,LETTER,SECONDNAME"
Set doc=GetObject ("E:\3-DataEssentials\Cardbox 3.0\MergeDocs\Etiket.docx","Word.Document")
Set mm=doc.MailMerge
mm.Destination=0 ' wdSendToNewDocument
mm.Execute

I get a Word error message: "requested object is not available (position in the macro: line 4, character 1)"
Line 4 is the line staring with mm.Destination=0 ...
but it does not help me to solve the problem.
Anyone?

bert

31-Oct-2011 12:26

Hi,
It's not (only) windows 7.
On my W7 starter machine I can replay the error, on a W7 prof I cannot (Off 2003).
I think it is the best to rewrite your macro (a little) using CreateObject instead of GetObject, then Open the etiket.docx and do your things.
Because I get same error I will try to find a solution.

regards
bert

bert

31-Oct-2011 12:51

Strange:
On the NOT working machine: I closed Cardbox + MS Word. Then tried it again. No error again.
So there is hope!

This piece of code does work. It works in the current Word document.
This is strange, because when I add a line 'aw.Documents.count' it results in 0...
So, on 'error resume next' will help you also to suppress the bad answers of Word?

    on error resume next
    Set x = GetObject(, "Word.Application")
    set aw = x.ActiveWindow
    set ad = aw.Document
    on error goto 0

    ... do your things

regards
bert

bert

1-Nov-2011 00:07

It's really an strange thing

I was testing again for some 30 minutes.
Did not work again. Error message. Requested object...

Then suddenly, it works. No problem any more.

Then I found http://support.microsoft.com/kb/238610.

Testing the suggested workaround seems necessary now.
regards
bert

mermayde

1-Nov-2011 11:49

Hi Bert,

Thanks for your speedy reply and suggestions.

First I tried your 1st suggestion, 31/10 12:51, but no changes so far.
Then I copy pasted the suggestion of the first workaround (not C++), of course changing Excel to Word, but that one gave an error already at line 1, character 17 (expected end of statement) in Private Declare Sub Sleep Lib "kernel32" _

Lost as ever ...

By the way, on my old PC (WinXP, Office2007) the macro worked well only when Word was already open; repeated use (or using a similar macro to a different document) was not possible; I had to close down Word, often even the PC. May be of help to solve?

bert

1-Nov-2011 12:32

Hi,
To day I tested the non-working pc after a clean reboot. Then it worked normal. Windows 7 - starter / MS Off 2003.
It sound to me a little unbelievable: the MS page (kb/238610) seems to tell that it takes some time before MS Word tells Windows it is allowed to perform 'getobject' from vbs or whatever it is. I tested it also using Visual Basic 6. Same result: errors.
But, after the spontaneous healing also VB6 worked. Amazing.

If I look to your macro Word seems only needed to print labels (filename: Etiket.docx)?
Why you do not print labels directly from Cardbox? Designing A4 label page in Cardbox is not difficult (read the Help file!).

If you really need Word and it is impossible for you to use Cardbox, I think you better can use CreateObject. That will open a new (hidden) copy of MS Word (no problem if Word is already open or not). In that copy you open your document. Then make new instance of Word visible. From that point it is all the same as your old macro.
regards
bert

mermayde

1-Nov-2011 12:55

Bert,
I will try to CreateObject as you suggested.
The Etiket indeed is to print labels, but I have a series of standard documents/letters etc. that (did) work similarly.
Best regards
Kees

Quick Reply

Please log in or register before trying to post a reply.

 
© 2010 Cardbox Software Limited   Home