Dynamic Word Doc Generation, Porting VBA to ASP

E

Enrique Rojas

Hello,

I have VBA code from an Access Form that I am porting over to ASP.

What the code does is takes a document template and inserts data tables
with values taken from an Access Database.

What I need to do have this code work in ASP. Generate a client side
word document based on the data in the database.

So far I have been able to port most of the code over. The Template
opens and values are being read from the database. However I run into a
problem with these lines.

objw.Selection.HomeKey Unit: = wdLine

and later

myTable.Cell(1, 1).Merge MergeTo:=myTable.Cell(2, 1)
myTable.Cell(2, 10).Merge MergeTo:=myTable.Cell(1, 10)
myTable.Cell(1, 2).Merge MergeTo:=myTable.Cell(1, 9)

Seems like commands with ":=" are no liked in ASP

I have been searching the internet for a solution where I can reword
that line but found nothing.

I have been using an ASP server called Baby ASP.

Can anyone confirm that these lines of code actualy do work in ASP.

Looking forward to a response.

Thank you.
 
D

Doug Robbins - Word MVP

I am not sure that this will overcome your problem, but in VBA,

Selection.HomeKey wdLine

can be used in place of

Selection.HomeKey Unit: = wdLine

and maybe you will need to use the Selection object for the cell merges

MyTable.Cell(1, 1).Range.Select
Selection.Extend
Selection.MoveDown wdLine, 1
Selection.Cells.Merge


--
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
 
H

Helmut Weber

Hi Enrique,

have a look at this one:

oTbl.Cell(1, 1).Merge oTbl.Cell(2, 1)
oTbl.Cell(2, 10).Merge oTbl.Cell(1, 10)
oTbl.Cell(1, 2).Merge oTbl.Cell(1, 9)

ok, if it works for you,
but you may run into trouble by trying to
access table cells by rowindex and columnindex
after having merged certain cells: Error 5941

In that case, keep very precisely track
of the number of cells you merge and which
and use something like:

oTbl.Range.Cells(1).Merge oTbl.Range.Cells(4)

There may still be other ways,
and of course, there is Doug's method, too.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
C

Cindy M.

Hi Enrique,
Seems like commands with ":=" are no liked in ASP

I have been searching the internet for a solution where I can reword
that line but found nothing.
When that's the case, then you have no choice but to type out every
parameter a method or property requires. For example, HomeKey has two
parameters:

Selection.HomeKey wdLine, false

Note that depending on the programming language, you might have to put
the parameters in parentheses

myTable.Cell(1, 1).Merge(myTable.Cell(1,3))

If you check Word's VBA Help for a method you're having problems with
you can see a list of the parameters. Parameters marked as [Optional]
can be left out; since optional parameters are always at the end, if
you don't need any of them, you can simply stop. So, HomeKey could
also be
Selection.HomeKey wdLine

because the second argument (Extend) is optional. Here's an example of
a method (fantasy, it doesn't exist) that has five parameters. None
are required, but it's the fifth one you want to use. In that case,
you have to use "empty commas" for the others in order to get to the
fifth one:

myMethod(,,,,true)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
E

Enrique Rojas

Thank you all for your suggestions.

I ran the code with your suggestions.

However the line "Selection.HomeKey wdLine" cause caused an error when
word document was being generated.

compared to before the line "Selection.HomeKey Unit: = wdLine" the
server just did not want to run at all. The word document did not even
open.

I just commented it out for now. The table merge suggestions were great
and are working fine.

Thanks to all
 
H

Helmut Weber

Hi Enrique,

if you want to put the cursor at the beginning
of the doc, for whatever reasons, you may use
activedocument.range(0,0).select

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
D

Doug Robbins - Word MVP

See Cindy's response.

--
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
 

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