K
Keith
I have Office 2003 and I have tried every variation I can think of to
use a variable for the worksheet name (to reflect the database) in a
mail merge. I hesitate to try a different connection, because the way
it is currently set up, it will read more than 255 characters (which
is a requirement).
I'll include my code below (up to the point I have a problem).
SQLStatement:="SELECT * FROM 'strExcelWkshtName'", _
I have also tried these (and many, many other) variations.
SQLStatement:="SELECT * FROM strExcelWkshtName", _
SQLStatement:="SELECT * FROM" & strExcelWkshtName, _
SQLStatement:="SELECT * FROM" & 'strExcelWkshtName', _
This statement (without the variable) works fine.
SQLStatement:="SELECT * FROM `'Planned Close Version 200-DB$'`", _
Notice that the variable strExcelFileName is used twice in the mail
merge and that works fine.
Just before my mail merge statements, I have 'commented out' the mail
merge line for the worksheet (database) that does not contain the
variable and works great.
====================================================================
Dim appXL As Excel.Application
Dim strExcelFileName As String, strExcelWkshtName As String
' Merge the data from the spreadsheet into a new word document based
off of this template.
'
Set appXL = GetObject(, "excel.application")
With appXL.ActiveWorkbook
strExcelFileName = .FullName
strExcelWkshtName = .ActiveSheet.Name & "$"
MsgBox strExcelFileName
MsgBox strExcelWkshtName
End With
'
' Merge the Word Template with the Excel data to create the User
Release Notes.
'
' , SQLStatement:="SELECT * FROM `'Planned Close Version 200-DB
$'`", _
ActiveDocument.MailMerge.MainDocumentType = wdCatalog
ActiveDocument.MailMerge.OpenDataSource Name:=strExcelFileName, _
ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User
ID=Admin;Data Source=strExcelFileName;Mode=Read;Extended
Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database", _
SQLStatement:="SELECT * FROM 'strExcelWkshtName'", _
SQLStatement1:="", SubType:=wdMergeSubTypeAccess
========================================================================
Anybody have any ideas?
Keith
use a variable for the worksheet name (to reflect the database) in a
mail merge. I hesitate to try a different connection, because the way
it is currently set up, it will read more than 255 characters (which
is a requirement).
I'll include my code below (up to the point I have a problem).
SQLStatement:="SELECT * FROM 'strExcelWkshtName'", _
I have also tried these (and many, many other) variations.
SQLStatement:="SELECT * FROM strExcelWkshtName", _
SQLStatement:="SELECT * FROM" & strExcelWkshtName, _
SQLStatement:="SELECT * FROM" & 'strExcelWkshtName', _
This statement (without the variable) works fine.
SQLStatement:="SELECT * FROM `'Planned Close Version 200-DB$'`", _
Notice that the variable strExcelFileName is used twice in the mail
merge and that works fine.
Just before my mail merge statements, I have 'commented out' the mail
merge line for the worksheet (database) that does not contain the
variable and works great.
====================================================================
Dim appXL As Excel.Application
Dim strExcelFileName As String, strExcelWkshtName As String
' Merge the data from the spreadsheet into a new word document based
off of this template.
'
Set appXL = GetObject(, "excel.application")
With appXL.ActiveWorkbook
strExcelFileName = .FullName
strExcelWkshtName = .ActiveSheet.Name & "$"
MsgBox strExcelFileName
MsgBox strExcelWkshtName
End With
'
' Merge the Word Template with the Excel data to create the User
Release Notes.
'
' , SQLStatement:="SELECT * FROM `'Planned Close Version 200-DB
$'`", _
ActiveDocument.MailMerge.MainDocumentType = wdCatalog
ActiveDocument.MailMerge.OpenDataSource Name:=strExcelFileName, _
ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User
ID=Admin;Data Source=strExcelFileName;Mode=Read;Extended
Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database", _
SQLStatement:="SELECT * FROM 'strExcelWkshtName'", _
SQLStatement1:="", SubType:=wdMergeSubTypeAccess
========================================================================
Anybody have any ideas?
Keith