
Signature
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
Thanks a lot! It worked like a charm! =)
If anybody is still interested in how it's done in VB.NET, here is a
code for the function:
'''''A function that takes one argument as a parameter and returns a
blank string if it's not successful,
''''' or "Success!" string or similar if everything works (for some
weird reason). The method
''''' that calls for this function is designed to catch the return
string and behave accordingly.
Private Function CreateWordDocument(ByVal someParameter As String) As
String
''Trying to opent a Word document, then create tables...
Try
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
''Visibility is set to true for debugging purposes. I'll
disable it, actually, later on
wrdApp.Visible = True
''The following is an imitation loop. In real application
I'll use DB connection and make it
''a WHILE loop that will go through all the records I need
to display in the tables
Dim i As Integer
Dim r As Word.Range
Dim t As Word.Table
For i = 1 To 2 ''Assuming for right now we only need 2
tables
r = wrdApp.ActiveDocument.Range
r.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
t = wrdApp.ActiveDocument.Tables.Add(Range:=r,
NumRows:=2, NumColumns:=2)
''Insert some data
t.Cell(1, 1).Range.InsertAfter("I'm a cell (1,1),
table number " & i)
t.Cell(2, 1).Range.InsertAfter("I'm a cell (2,1),
table number " & i)
r = wrdApp.ActiveDocument.Range
r.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
If i < 2 Then
r.InsertAfter(vbCr)
End If
Next i
Return "Success!"
Catch ex As Exception
Return ""
End Try
Return ""
end function
Doug, thanks a lot for your help! =)
VJ.
Perry - 09 Feb 2007 12:04 GMT
Great that with the help of Doug you could make things work
in VB.net, but
> '''''A function that takes one argument as a parameter and returns a
> blank string if it's not successful,
The way I read yr code, the function will always return ""
--
Krgrds,
Perry
System: Vista/Office Ultimate
> Thanks a lot! It worked like a charm! =)
>
[quoted text clipped - 57 lines]
> Doug, thanks a lot for your help! =)
> VJ.
Vassili.King@gmail.com - 13 Feb 2007 22:36 GMT
Perry,
Actually, if the Try statement doesn't fail, after the tables are
created you'll hit the Return "Success" statement which would
terminate the function and return "Success" as a string. If there were
an exception, ther the Return "" would be initiated.
Perry - 15 Feb 2007 00:53 GMT
It's one out of either ...
If Return statement is facilitated in each branch if the Try/Catch/Finally
block,
it is redundant to use it afterwards ...
Minor point but nevertheless...
Krgrds,
Perry
> Perry,
>
> Actually, if the Try statement doesn't fail, after the tables are
> created you'll hit the Return "Success" statement which would
> terminate the function and return "Success" as a string. If there were
> an exception, ther the Return "" would be initiated.