B
BurtArkin
Using XP Pro, Access2002, Word2002. Access program has msword.olb library
registered. My merge works to a point. My code opens a word document (or
dot file), renames and saves the file with a unique name based on program
data. I then have code that is supposed to format the new document. On the
computer that crashed last week, everything worked properly. I had to buy a
new machine and re-install Office. Now, the code works until I tell it to
format the document. The code is shown below. PLEASE help--I'm going NUTS!
I'd appreciate the help. Thank you.
If KindOfDoc = 1 Then
Dim WApp, CalWDoc As Object
Set WApp = CreateObject("Word.application")
WApp.Visible = True
WApp.Documents.Add Template:="M:\Access
New\Winword\LindaL\Arkin\DBNewCORP.DOC", NewTemplate:=False
If WApp.ActiveWindow.View.SplitSpecial <> wdPaneNone Then
WApp.ActiveWindow.Panes(2).Close
End If
WApp.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
WApp.Selection.WholeStory
Dim myfilename As String
myfilename = "M:\Access New\Winword\LindaL\Arkin\" & "Volume" &
Me.PlanNumber & "-" & Me.VolProtMasterID
WApp.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
WApp.ActiveDocument.SaveAs FileName:=myfilename,
FileFormat:=wdFormatDocument, AddToRecentFiles:=True
End If
'following finds source
WApp.ActiveDocument.MailMerge.MainDocumentType = 0 'wdFormLetters '0
WApp.ActiveDocument.MailMerge.OpenDataSource Name:= _
"M:\Access New\NewVolume.mdb", 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=M:\Access New\NewVolume.mdb;Mode=Read;Extended Properties="""";Jet
OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB
atabase
Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB
a" _
, SQLStatement:="SELECT * FROM `SelectionsTableTemp`",
SQLStatement1:="", SubType:=1
WApp.Selection.Find.ClearFormatting
'the following section does not do its job
Dim rngDocument As Object 'Range
''Find each instance of BLD and make entire paragraph bold, then delete "BLD"
Set rngDocument = WApp.ActiveDocument.Range
With rngDocument.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "BLD"
.Forward = True
.Wrap = 0 'wdFindStop
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
While .Found
rngDocument.Paragraphs.First.Range.Font.Bold = True
rngDocument.Paragraphs.Alignment = wdAlignParagraphCenter 'my addition
for centering
rngDocument.Delete
rngDocument.MoveEnd 6 'wdStory
.Execute
Wend
End With
registered. My merge works to a point. My code opens a word document (or
dot file), renames and saves the file with a unique name based on program
data. I then have code that is supposed to format the new document. On the
computer that crashed last week, everything worked properly. I had to buy a
new machine and re-install Office. Now, the code works until I tell it to
format the document. The code is shown below. PLEASE help--I'm going NUTS!
I'd appreciate the help. Thank you.
If KindOfDoc = 1 Then
Dim WApp, CalWDoc As Object
Set WApp = CreateObject("Word.application")
WApp.Visible = True
WApp.Documents.Add Template:="M:\Access
New\Winword\LindaL\Arkin\DBNewCORP.DOC", NewTemplate:=False
If WApp.ActiveWindow.View.SplitSpecial <> wdPaneNone Then
WApp.ActiveWindow.Panes(2).Close
End If
WApp.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
WApp.Selection.WholeStory
Dim myfilename As String
myfilename = "M:\Access New\Winword\LindaL\Arkin\" & "Volume" &
Me.PlanNumber & "-" & Me.VolProtMasterID
WApp.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
WApp.ActiveDocument.SaveAs FileName:=myfilename,
FileFormat:=wdFormatDocument, AddToRecentFiles:=True
End If
'following finds source
WApp.ActiveDocument.MailMerge.MainDocumentType = 0 'wdFormLetters '0
WApp.ActiveDocument.MailMerge.OpenDataSource Name:= _
"M:\Access New\NewVolume.mdb", 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=M:\Access New\NewVolume.mdb;Mode=Read;Extended Properties="""";Jet
OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB
Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB
, SQLStatement:="SELECT * FROM `SelectionsTableTemp`",
SQLStatement1:="", SubType:=1
WApp.Selection.Find.ClearFormatting
'the following section does not do its job
Dim rngDocument As Object 'Range
''Find each instance of BLD and make entire paragraph bold, then delete "BLD"
Set rngDocument = WApp.ActiveDocument.Range
With rngDocument.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "BLD"
.Forward = True
.Wrap = 0 'wdFindStop
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
While .Found
rngDocument.Paragraphs.First.Range.Font.Bold = True
rngDocument.Paragraphs.Alignment = wdAlignParagraphCenter 'my addition
for centering
rngDocument.Delete
rngDocument.MoveEnd 6 'wdStory
.Execute
Wend
End With