I am trying to merge the results from an SQL run by an asp page into a
word document but do not know where to start. I would like to do it
like a mail merge. Can any one provide some suggestions that might
help. Purchasing extra software is not an option.

Re: help merging a web page into a word document by JHP

JHP
Tue Jan 03 10:45:49 CST 2006

Here is some code (I remarked out 3 lines that were used to remove a page
break)...
*** Watch for word wrap ***
This is only one route - hope some of the code can help:

MergeFile.doc - Word document that consists of headers and values (create
this on the fly from your SQL return)
(headers separated by tabs followed by a return - values separated by tabs
followed by a return)

example

FIRST MIDDLE LAST
John H. Doe

InsertFile.doc - Word document with predefined merge fields that point to
MergeFile.doc

NewFile.doc - Created from InsertFile.doc and fully merged; populated from
MergeFile.doc

Option Explicit

Dim objWord

Set objWord = CreateObject("Word.Application")
objWord.Visible = False
objWord.ScreenUpdating = False
objWord.Documents.Add
objWord.ActiveDocument.ShowSpellingErrors = False
objWord.ActiveDocument.ShowGrammaticalErrors = False
objWord.Options.SaveInterval = 0
objWord.ActiveDocument.PageSetup.TopMargin = ".30"
objWord.ActiveDocument.PageSetup.BottomMargin = ".30"
objWord.ActiveDocument.PageSetup.LeftMargin = ".26"
objWord.ActiveDocument.PageSetup.RightMargin = ".26"
objWord.ActiveDocument.PageSetup.Gutter = "0"
objWord.ActiveDocument.PageSetup.HeaderDistance = ".10"
objWord.ActiveDocument.PageSetup.FooterDistance = ".10"
objWord.ActiveDocument.MailMerge.OpenDataSource("C:\MergeFile.doc")
objWord.Selection.EndKey(6)
objWord.Selection.InsertFile("C:\InsertFile.doc")
objWord.ActiveDocument.MailMerge.Destination = "0"
objWord.ActiveDocument.MailMerge.Execute(False)
'objWord.Selection.EndKey(6)
'objWord.Selection.TypeBackspace
'objWord.Selection.Delete
objWord.ActiveDocument.SaveAs("C:\NewFile.doc")
objWord.ActiveDocument.Close()
objWord.ActiveDocument.Close(0)
objWord.Application.Quit()
Set objWord = Nothing

"stumblingAlong" <scott.grenham@gmail.com> wrote in message
news:1136304258.078970.40790@o13g2000cwo.googlegroups.com...
>I am trying to merge the results from an SQL run by an asp page into a
> word document but do not know where to start. I would like to do it
> like a mail merge. Can any one provide some suggestions that might
> help. Purchasing extra software is not an option.
>



Re: help merging a web page into a word document by stumblingAlong

stumblingAlong
Wed Jan 18 07:34:17 CST 2006

I am having a problem with writing to the doc that is created on the
fly. I keep getting a '800a0046' permission denied error. I thought
that I was doing something wrong so I tried using an example of a
guestbook that I had seen work before. I get the same error. The code
that is giving it a problem in the guestbook example is:

' open the guestbook, 8 is for appending
' create the guestbook if it does not exist
Set textFile = fileObject.OpenTextFile( guestbook, 8, True )

>From past experience I know that if I do not find out what is causing
this problem I will be waiting for a very long time for the person in
charge of running the server to fix it. Obviously a permission setting
needs to be changed but almost everything I have found about this error
is connected to email. Does anyone know what the permissions need to
be set to on a 2003 MS Web server to make this work?