mail merge 2007 line spacing

  • Thread starter darren via OfficeKB.com
  • Start date
D

darren via OfficeKB.com

Hi

I am merging from an access 2003 database to a 2003 word doc. However, when a
2007 user opens it it has the line spacing issue mentioned in
http://support.microsoft.com/kb/921174

The word document is opened from access and I would like to perform the noted
task in the above article in vba i.e when opening the document for 2007
version users set the style set to "Word 2003".

All help appreciated as I'm not too hot on Word.

Thanks in advance.
 
D

Doug Robbins - Word MVP

You could just manually change the line spacing in the document one time and
save it in that format before it used by Access. As mentioned, that only
has to be done the one time.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
D

darren via OfficeKB.com

Thanks Doug but as I said I am not to hot on Word and I am unclear. The
'master' is in Word2003 and as such the line spacing is fine. It is this
master that gets copied to the individual users along with their Access front
end. It is only when the document is opened in Word2007 that the spacing is
wrong.

The document has to be in 2003 format as most users are still on this but
gradually more are moving over to 2007. Are you suggesting I open it in 2007
(keeping the 2003 format) correct the line spacing then save it still in 2003
format? If so, will this affect how it is formatted in 2003?

My concern is that I have a whole library of merge documents and do not want
to have correct all of them for this issue. My idea was that when the merging
to the document it indentifies if the word app is 2007 (e.g. if objApp.
Version >=12 then ) and if so programmatically change the style set to 'Word
2003'. This is the code in access that I currently use to open the merge
document. It is this code that I wish to revise as mentioned above:

Function fnMergeIt(strDoc As String, strTbl As String, blnOptText As Boolean,
DocID As Integer)
On Error GoTo Err_fnMergeIt

Dim objApp As Word.Application
Dim objWord As Word.Document
Dim objStyle As Word.Style
Dim strConnection As String
Dim path As String
Dim strDataDir As String
Dim ReadOnly As Boolean
Dim PrintOnly As Boolean

ReadOnly = DLookup("[ReadOnly]", "UsystblDocuments", "[DocID] = " & DocID &
"")
PrintOnly = DLookup("[PrintOnly]", "UsystblDocuments", "[DocID] = " & DocID &
"")

strConnection = "DSN=MS Access Database;DBQ=" & CurrentProject.FullName & "
;FIL=MS Access;"

strDoc = Chr$(34) & CurrentProject.path & "\" & strDoc & Chr$(34)
'Debug.Print strDoc

Set objApp = CreateObject("Word.Application")

Set objWord = objApp.Documents.Open(strDoc, , ReadOnly, , , , , "Document")

' Set the mail merge data source
objWord.MailMerge.OpenDataSource _
Name:=CurrentProject.FullName, _
LinkToSource:=True, _
Connection:=strConnection, _
ReadOnly:=True, _
SQLStatement:="SELECT * FROM [" & strTbl & "]"

objWord.MailMerge.ViewMailMergeFieldCodes = False

' Check and action optional text
If blnOptText = True Then
For Each objStyle In objWord.Styles
If objStyle.NameLocal = "EEConfOpt" Then
With objStyle.Font
.Hidden = fnOptionalText(objStyle.NameLocal, DocID)
End With
End If
Next objStyle
objWord.UpdateStyles
End If

If PrintOnly = False Then
' Make Word visible.
objApp.Visible = True
objApp.Activate
Else
objApp.Visible = False
objWord.Save
objWord.Close
objApp.Quit
End If

Exit_fnMergeIt:
Set objWord = Nothing
Set objApp = Nothing
Exit Function

Err_fnMergeIt:
If Err.Number = 5922 Then
objWord.Close False
objApp.Quit
End If
objWord.Close False
objApp.Quit
MsgBox "fnMergeIt: " & Err.Number & " - " & Err.Description, ,
p_strSSLProduct
Resume Exit_fnMergeIt

End Function


All help and advice appreciated.
 
D

Doug Robbins - Word MVP

The issue is that the document undoubtably is formatted with the Normal
Style and in Word 2007, by default, that style is defined differently from
the default in Word 2003. Aside from that however, some of your users may
have re-defined the normal style to suit themselves. So, as long as the
document is formatted with the Normal Style, it will be displayed in what
ever format is defined as the Normal Style on the machine that it is opened
with.

The best thing for you to do will be to modify your code as follows:

Function fnMergeIt(strDoc As String, strTbl As String, blnOptText As
Boolean,
DocID As Integer)
On Error GoTo Err_fnMergeIt

Dim objApp As Word.Application
Dim objWord As Word.Document
Dim objStyle As Word.Style
Dim strConnection As String
Dim path As String
Dim strDataDir As String
Dim ReadOnly As Boolean
Dim PrintOnly As Boolean

ReadOnly = DLookup("[ReadOnly]", "UsystblDocuments", "[DocID] = " & DocID &
"")
PrintOnly = DLookup("[PrintOnly]", "UsystblDocuments", "[DocID] = " & DocID
&
"")

strConnection = "DSN=MS Access Database;DBQ=" & CurrentProject.FullName & "
;FIL=MS Access;"

strDoc = Chr$(34) & CurrentProject.path & "\" & strDoc & Chr$(34)
'Debug.Print strDoc

Set objApp = CreateObject("Word.Application")

Set objWord = objApp.Documents.Open(strDoc, , ReadOnly, , , , , "Document")

'Code to control the paragraph format
With objWord.Range.ParagraphFormat
.LineSpacingRule = wdLineSpaceSingle
.SpaceBefore = 0
.SpaceAfter = 0
End With

' Set the mail merge data source
objWord.MailMerge.OpenDataSource _
Name:=CurrentProject.FullName, _
LinkToSource:=True, _
Connection:=strConnection, _
ReadOnly:=True, _
SQLStatement:="SELECT * FROM [" & strTbl & "]"

objWord.MailMerge.ViewMailMergeFieldCodes = False

' Check and action optional text
If blnOptText = True Then
For Each objStyle In objWord.Styles
If objStyle.NameLocal = "EEConfOpt" Then
With objStyle.Font
.Hidden = fnOptionalText(objStyle.NameLocal, DocID)
End With
End If
Next objStyle
objWord.UpdateStyles
End If

If PrintOnly = False Then
' Make Word visible.
objApp.Visible = True
objApp.Activate
Else
objApp.Visible = False
objWord.Save
objWord.Close
objApp.Quit
End If

Exit_fnMergeIt:
Set objWord = Nothing
Set objApp = Nothing
Exit Function

Err_fnMergeIt:
If Err.Number = 5922 Then
objWord.Close False
objApp.Quit
End If
objWord.Close False
objApp.Quit
MsgBox "fnMergeIt: " & Err.Number & " - " & Err.Description, ,
p_strSSLProduct
Resume Exit_fnMergeIt

End Function

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
darren via OfficeKB.com said:
Thanks Doug but as I said I am not to hot on Word and I am unclear. The
'master' is in Word2003 and as such the line spacing is fine. It is this
master that gets copied to the individual users along with their Access
front
end. It is only when the document is opened in Word2007 that the spacing
is
wrong.

The document has to be in 2003 format as most users are still on this but
gradually more are moving over to 2007. Are you suggesting I open it in
2007
(keeping the 2003 format) correct the line spacing then save it still in
2003
format? If so, will this affect how it is formatted in 2003?

My concern is that I have a whole library of merge documents and do not
want
to have correct all of them for this issue. My idea was that when the
merging
to the document it indentifies if the word app is 2007 (e.g. if objApp.
Version >=12 then ) and if so programmatically change the style set to
'Word
2003'. This is the code in access that I currently use to open the merge
document. It is this code that I wish to revise as mentioned above:

Function fnMergeIt(strDoc As String, strTbl As String, blnOptText As
Boolean,
DocID As Integer)
On Error GoTo Err_fnMergeIt

Dim objApp As Word.Application
Dim objWord As Word.Document
Dim objStyle As Word.Style
Dim strConnection As String
Dim path As String
Dim strDataDir As String
Dim ReadOnly As Boolean
Dim PrintOnly As Boolean

ReadOnly = DLookup("[ReadOnly]", "UsystblDocuments", "[DocID] = " & DocID
&
"")
PrintOnly = DLookup("[PrintOnly]", "UsystblDocuments", "[DocID] = " &
DocID &
"")

strConnection = "DSN=MS Access Database;DBQ=" & CurrentProject.FullName &
"
;FIL=MS Access;"

strDoc = Chr$(34) & CurrentProject.path & "\" & strDoc & Chr$(34)
'Debug.Print strDoc

Set objApp = CreateObject("Word.Application")

Set objWord = objApp.Documents.Open(strDoc, , ReadOnly, , , , ,
"Document")

' Set the mail merge data source
objWord.MailMerge.OpenDataSource _
Name:=CurrentProject.FullName, _
LinkToSource:=True, _
Connection:=strConnection, _
ReadOnly:=True, _
SQLStatement:="SELECT * FROM [" & strTbl & "]"

objWord.MailMerge.ViewMailMergeFieldCodes = False

' Check and action optional text
If blnOptText = True Then
For Each objStyle In objWord.Styles
If objStyle.NameLocal = "EEConfOpt" Then
With objStyle.Font
.Hidden = fnOptionalText(objStyle.NameLocal, DocID)
End With
End If
Next objStyle
objWord.UpdateStyles
End If

If PrintOnly = False Then
' Make Word visible.
objApp.Visible = True
objApp.Activate
Else
objApp.Visible = False
objWord.Save
objWord.Close
objApp.Quit
End If

Exit_fnMergeIt:
Set objWord = Nothing
Set objApp = Nothing
Exit Function

Err_fnMergeIt:
If Err.Number = 5922 Then
objWord.Close False
objApp.Quit
End If
objWord.Close False
objApp.Quit
MsgBox "fnMergeIt: " & Err.Number & " - " & Err.Description, ,
p_strSSLProduct
Resume Exit_fnMergeIt

End Function


All help and advice appreciated.

--
Darren

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200904/1
 
D

darren via OfficeKB.com

Ok cheers Doug, I'll try that.

To further my understanding of Word, you mention that each normal.dot is
local to the user. If so, if I create my own 'style' for these documents how
would the merged document pick this up? Would be automatically distirbuted
with the merged document?

Thanks again for your time and patience.
 

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