2012-02-06 6 views
0
Sub t() 

Dim File As String 
File = "C:\Users\Tin\Desktop\a.docx" 

Dim oWord As Word.Application 
Set oWord = New Word.Application 
Dim oDoc As Word.Document 
Set oDoc = oWord.Documents.Open(File) 
oWord.Visible = True 

With oDoc 

Dim Table1 As Word.Table 
Set Table1 = .Tables.Add(Range:=.Range, NumRows:=2, NumColumns:=2) 

Table1.Borders(wdBorderTop).LineStyle = wdLineStyleSingle 
Table1.Borders(wdBorderRight).LineStyle = wdLineStyleSingle 
Table1.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle 
Table1.Borders(wdBorderLeft).LineStyle = wdLineStyleSingle 
Table1.Borders(wdBorderHorizontal).LineStyle = wdLineStyleSingle 
Table1.Borders(wdBorderVertical).LineStyle = wdLineStyleSingle 

Table1.Rows.Height = 50 

Dim lLeft As Long 
Dim lTop As Long 
Dim Rng As Word.Range 

Set Rng = .Tables(1).Cell(1, 1).Range 

Dim Shp As Word.Shape 
    lLeft = .Tables(1).Cell(1, 1).Range.Information(wdHorizontalPositionRelativeToPage) + 50 
    lTop = .Tables(1).Cell(1, 1).Range.Information(wdVerticalPositionRelativeToPage) + 20 
    Debug.Print (lLeft) 
    Debug.Print (lTop) 

Set Shp = .Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, Left:=lLeft, _ 
    Top:=iTop, Width:=20, Height:=20, Anchor:=Rng) 
End With 

End Sub 

Excel에서 Word를 자동화하고 있습니다. 텍스트 위치를 조정하려했지만 실패했습니다. 항상 테이블 바깥에 있습니다. Word 자체에서 자동화 할 수 있지만 Word를 제어하는 ​​Excel에서 TextBox는 위치 지정과 관련하여 나에게 이해할 수없는 것처럼 보입니다.테이블 셀 안에 Textbox를 추가하는 방법은 무엇입니까?

답변

0

이전 질문 이었지만 어쨌든 조사하고 싶었습니다. 나는 당신의 코드 (Word Object Library에 추가 된 참조가있는 Excel 매크로)를 시도해보고 잘못된 것을 찾지 못했습니다. 코드가 예상대로 작동합니다. 첫 번째 셀 안에 사각형 모양이 있습니다.

Office 2010 (이탈리아어)을 사용하고 있습니다.

관련 문제