PDA

View Full Version : backward compatibility



one too many
12-13-2008, 02:16 PM
I have a macro written which makes envelopes from a word template .doc file (it's an DL envelope with fields: "name", "surname", "address" and "city" for mail merging) and a .xls data base.It's written in Excel 2007 (Slovene language).
I have problems with compatibility. It only works on my computer! My brother has the same Office (of course he has Excel and Word installed) but WinXP (I have Vista Businees) and it stops when macro gets to the Word part of code (I had include Word 12.0 object library). I forgot what was the error, but I think it was " Compile error: Can't find project or library" at first line of word code.
On other computers (older Office) it's not working at all. It stops at first line (Sub Kuverte()). The error is: " Compile error: Can't find project or library".
Guess library aren't backward compatible? But why it doesn't work on other office 2007?
I copied code in excel 2000 VB and then stops with error "Named argument not found"

WdDoc.MailMerge.OpenDataSource Name:= _
FilePath(ThisWorkbook.FullName) & "Kopijaclanstvo+2008-09.xls", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=ExcelAdress;Mode=Read;"Extended Properties=""HDR=YES;IMEX=1;""; _
Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=35;Jet OLEDB" _
, SQLStatement:="SELECT * FROM `'Za Posiljanje$'`", SQLStatement1:="", _
SubType:=wdMergeSubTypeAccess It stops in the last line (SubType:=wdMergeSubTypeAccess)

mdmackillop
12-13-2008, 04:01 PM
Untested, but try omitting that item

WdDoc.MailMerge.OpenDataSource Name:= _
FilePath(ThisWorkbook.FullName) & "Kopijaclanstvo+2008-09.xls", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=ExcelAdress;Mode=Read;"Extended Properties=""HDR=YES;IMEX=1;""; _
Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=35;Jet OLEDB" _
, SQLStatement:="SELECT * FROM `'Za Posiljanje$'`", SQLStatement1:=""

Bob Phillips
12-13-2008, 04:14 PM
Show us the code where you assign WdDoc.

If it is something like


Dim WdApp As Word.Application
Dim WdDoc As Word.Document

Set WdApp = New Word.Application
Set WdDoc = WdApp.Documents.Add


maybe change it to



Dim WdApp As Object
Dim WdDoc As Object

Set WdApp = CreateObject("Word.Application")
Set WdDoc = WdApp.Documents.Add

one too many
12-14-2008, 09:50 AM
This is word part of code (before this are few for loops that prepares second sheet for mail merge):

Dim appWd As Object
Dim WdDoc As Object

Set appWd = CreateObject("Word.Application")
appWd.Visible = True

appWd.Activate

Set WdDoc = appWd.Documents.Open(FilePath(ThisWorkbook.FullName) & "Kuverte.doc")
With appWd

WdDoc.Activate

ExcelFolder = FilePath(ThisWorkbook.FullName) & "Kopijaclanstvo+2008-09.xls"

WdDoc.MailMerge.OpenDataSource Name:= _
FilePath(ThisWorkbook.FullName) & "Kopijaclanstvo+2008-09.xls", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=ExcelAdress;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;""; _
Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=35;Jet OLEDB" _
, SQLStatement:="SELECT * FROM `'Za Posiljanje$'`", SQLStatement1:="", _
-> SubType:=wdMergeSubTypeAccess

With WdDoc.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
End With

Set appWd = Nothing
Set WdDoc = Nothing

OK, on my brother's computer it stops at red line. I change it to: New Word.Application and it returns the same error.
With orange command set as comment it stops few lines bellow (.Destination = ...) but that is normal.

And now for something completely different: it perfectly works on father's word 2003! And he uses English office (there are known problems that Slovene Office calls "Knjižnica" and not "Library" (you can figure out that knjižnica means library in Slovene)!

one too many
12-14-2008, 10:57 AM
Unfortunately it doesn't work on another english office 2003 (tested on another PC)

Bob Phillips
12-14-2008, 11:27 AM
Have you tried it without the subtype property as MD suggested?

one too many
12-15-2008, 06:48 AM
Yes.
Without wdMergeSubTypeAccess it is completely the same.
Without whole subtype it still doesn't work, but there is no error because word freezes.