Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word and tables 1

Status
Not open for further replies.

brd24gor

MIS
May 18, 2005
123
US
Alright, not sure if I'm in the right place here, but you guys have been helpful to me in the past. I am currently writing an app in C# that is generating reports in Word. I'm using VBA code to guide me as the code is 75% similar.

I need to know how to go about deselecting a table so when I insert text, the table doesn't get written over. Here is the chunk of VBA I'm using as reference to do this:

Code:
    Selection.Tables(1).Select
    With Selection.Tables(1)
        .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
        .Borders(wdBorderRight).LineStyle = wdLineStyleNone
        .Borders(wdBorderTop).LineStyle = wdLineStyleNone
        .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
        .Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
        .Borders(wdBorderVertical).LineStyle = wdLineStyleNone
        .Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
        .Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
        .Borders.Shadow = False
    End With
Selection.TypeText Text:="test text"

Question is: 1) Is there a better way to take out the borders without selecting the table?
-and-
2) If not, how do I go about deselecting the table?

An answer in VBA is fine, I can convert it to C#.

Thanks!
--Brad

PS: Here is the C# code I'm using in case anyone is interested. In it, I am able to put text in the cell I want but the table remains selected and highlighted.
Code:
			myWord.Selection.Tables[1].Select();
			myWord.Selection.Tables[1].Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleNone;
			myWord.Selection.Tables[1].Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleNone;
			myWord.Selection.MoveLeft(ref wdCharacter, ref Count, ref wdExtend);
			myWord.Selection.MoveDown(ref wdLine, ref Count, ref wdExtend);
			
			myWord.Selection.Tables[1].Cell(2,1).Range.Text = "This is a cell";
 


Hi,

take a look at this code
Code:
    Dim r, c
    With ActiveDocument.Tables(1)
        .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
        .Borders(wdBorderRight).LineStyle = wdLineStyleNone
        .Borders(wdBorderTop).LineStyle = wdLineStyleNone
        .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
        .Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
        .Borders(wdBorderVertical).LineStyle = wdLineStyleNone
        .Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
        .Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
        .Borders.Shadow = False
        For Each r In .Rows
            For Each c In .Columns
                .Cell(r.Index, c.Index).Range.Text = "test text" & r.Index & c.Index
            Next
        Next
        
    End With

Skip,

[glasses] [red]Be advised:[/red]We know Newton's 3 Laws. But did you hear about the [red]FOURTH???[/red]
Only ONE fig per cookie![tongue]
 
Ahh, ActiveDocument is my friend.

Thanks again!!

--Brad
 
Just remember:

ActiveDocument.Tables(1) = the first table in the document
Selection.Tables(1) = the table the Selection is in.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top