AboutSyed Rizwan Muhammad Rizvi Expertise I can answers questions regarding web based and desktop based programming in VB.Net. Which can include SOAP, XML, Custom Controls, COM Interoperability etc.
Experience Have been working in this specific area for last 2 years previously I was a VB 6 Developer with experties in other languages as well. Total 10 years of programming experience.
Expert: Syed Rizwan Muhammad Rizvi Date: 4/3/2008 Subject: vb 2005...trying to insert value to cell in word table
Question QUESTION: Hi Syed,
Maybe you can shed some light on my problem... I am using vb 2005 and I do a find for a variable in a "table" word document. Once I find the variable in the word table, I want to replace the 5 cells with 5 items that I have selected... Here is a snippit of the code that I have:
Dim myWordApp As Microsoft.Office.Interop.Word.Application = New Microsoft.Office.Interop.Word.Application
Dim myWordDoc As Microsoft.Office.Interop.Word.Document = New Microsoft.Office.Interop.Word.Document
'
' If selected document contains variable @Claims-5-col, then do table
' inserts of row information
'
blnClaims = False
blnClaims = myWordDoc.Content.Find.Execute(FindText:="@CLaims-5-col")
If blnClaims Then
'
' do process to insert returned Claim variables for each row found in colClaims
' colection
'
Dim intClaimCellIDX As Integer = 0
Dim strPrevProviderName As String = ""
For intClaimsIDX = 1 To (colClaims.Count - 1)
'
' provider name process
'
If colClaims(intClaimsIDX).clm_prov_name = strPrevProviderName Then
myWordDoc.Application.WordBasic.ToString.Insert(1, " ")
Else
'myWordDoc.Content.Cells.Application.WordBasic.ToString.Insert(1, colClaims(intClaimsIDX).clm_prov_name)
'myWordDoc.Application.WordBasic.ToString.Insert(1, colClaims(intClaimsIDX).clm_prov_name)
myWordDoc.Application.WordBasic.ToString.Insert(1, colClaims(intClaimsIDX).clm_prov_name)
strPrevProviderName = colClaims(intClaimsIDX).clm_prov_name
End If
ANSWER: If the maximum value for colClaims.Count = 5 then you should be starting your loop from 0 rather than 1.
See if that fixes your problem, which you actually forgot to mention in your question.
---------- FOLLOW-UP ----------
QUESTION: My question is what are the word objects to add a new row with 5 cells and what is the instructions to go to the next cell (1 to 5)... the code I sent you was just a sampling...
Thanks Syed
Answer Code for creating a table:
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=5, NumColumns:= _
8, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
End With