Interop Word

paulthepaddy

Well-known member
Joined
Apr 9, 2011
Messages
222
Location
UK
Programming Experience
Beginner
hi all this is my code and under the code is my problem, sorry if i seem short, just day turning into a bad one lol
VB.NET:
Dim oWord As Word.Application
        Dim oDoc As Word.Document
        If System.IO.File.Exists(Application.StartupPath & "\Templates\invoice.dotx") Then
            oWord = CreateObject("Word.Application")
            oWord.Visible = True
            oDoc = oWord.Documents.Add(Application.StartupPath & "\Templates\invoice.dotx")
            Dim rowsbefore As Integer = (oDoc.Tables(1).Rows.Count / 2) + 1
            oDoc.Bookmarks.Item("CustomerName").Range.Text = customer_Name
            oDoc.Bookmarks.Item("AddressLine1").Range.Text = Address_Line1
            oDoc.Bookmarks.Item("AddressLine2").Range.Text = Address_Line2
            oDoc.Bookmarks.Item("Postcode").Range.Text = Postcode
            oDoc.Bookmarks.Item("PhoneNumber").Range.Text = phoneNumber
            oDoc.Bookmarks.Item("Invoice_Number").Range.Text = Invoice_Name
            oDoc.Bookmarks.Item("Date").Range.Text = Format(System.DateTime.Today, "dd / MM / yyyy")

           [COLOR=red] If Form_Invoice_Management.car1.finished = True Then
                oDoc.Tables(1).Cell(2, 1).Range.Text = Form_Invoice_Management.car1.Model
                oDoc.Tables(1).Cell(2, 2).Range.Text = Form_Invoice_Management.car1.Colour
                oDoc.Tables(1).Cell(2, 3).Range.Text = Form_Invoice_Management.car1.Reg
                [COLOR=seagreen]For i = 0 To Form_Invoice_Management.car1.damage.Count - 1
                    oDoc.Tables(1).Cell(2, 4).Range.Text &= Form_Invoice_Management.car1.damage(i)
                Next[/COLOR]
                oDoc.Tables(1).Cell(2, 5).Range.Text = Form_Invoice_Management.car1.Total
                Total_Discount += Form_Invoice_Management.car1.Discount
                Total_Subtotal += Form_Invoice_Management.car1.Total
                oDoc.Tables(1).Rows.Add(oDoc.Tables(1).Rows(rowsbefore))
            End If[/COLOR]
            If Form_Invoice_Management.car2.finished = True Then
                oDoc.Tables(1).Cell(3, 1).Range.Text = Form_Invoice_Management.car2.Model
                oDoc.Tables(1).Cell(3, 2).Range.Text = Form_Invoice_Management.car2.Colour
                oDoc.Tables(1).Cell(3, 3).Range.Text = Form_Invoice_Management.car2.Reg
               [COLOR=deepskyblue] For i = 0 To Form_Invoice_Management.car2.damage.Count - 1
                    oDoc.Tables(1).Cell(3, 4).Range.Text &= Form_Invoice_Management.car2.damage(i)
                Next[/COLOR]
                oDoc.Tables(1).Cell(3, 5).Range.Text = Form_Invoice_Management.car2.Total
                Total_Discount += Form_Invoice_Management.car2.Discount
                Total_Subtotal += Form_Invoice_Management.car2.Total
                oDoc.Tables(1).Rows.Add(oDoc.Tables(1).Rows(rowsbefore))
            End If

For some reson the code in red is being executed but the data being processes in green is being mixed with the code in blue.

instead of cell 2,4 being filled with data and the cell 3,4 being filled

cell 3,4 is being filled with ALL data
 

paulthepaddy

Well-known member
Joined
Apr 9, 2011
Messages
222
Location
UK
Programming Experience
Beginner
SOLVED Interop Word

had to replace this code
VB.NET:
oDoc.Tables(1).Rows.Add(oDoc.Tables(1).Rows(rowsbefore))
with this code
VB.NET:
oDoc.Tables(1).Rows.Last.Range.Rows.Add()
 
Top Bottom