AllExperts > Experts 
Search      

VB.NET

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More VB.NET Answers
Question Library

Ask a question about VB.NET
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Syed 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.

 
   

You are here:  Experts > Computing/Technology > Basic > VB.NET > vb 2005...trying to insert value to cell in word table

Topic: VB.NET



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

Code for inserting a new row:

Selection.InsertRowsBelow 1

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.