如何更改页脚中 table 的大小和位置?
How to change the size and the position of the table in the footer?
我需要使用 excel vba 在 .docx 的页脚中创建一个 table。我有我的手机,但你知道是否有任何方法可以改变它的大小和位置?谢谢
编辑:我发现了这个:https://docs.microsoft.com/en-us/office/vba/api/word.tables.add
但是我不知道在 DefaultTableBehavior 和 AutoFitBehavior 中放什么
Option Explicit
Sub test()
'Déclaration des variables
Dim I As Integer
Dim Fichier As String
Dim MaFeuille As Worksheet
Dim ListeBordures As Variant
Dim word_app As Word.Application, word_fichier As Word.Document, tbl As Word.Table, rngCell As Word.Range
'On récupère le fichier test
Fichier = ActiveWorkbook.Path & "\" & "test.docx"
'Ouverture de word
Set word_app = CreateObject("Word.Application")
With word_app
.Visible = True
.WindowState = 1
Set word_fichier = .Documents.Open(Fichier)
End With
'Test tableau bas de page
With word_fichier
Set tbl = .Tables.Add(.Sections(1).Footers(wdHeaderFooterPrimary).Range, 1, 1)
ListeBordures = Array(-1, -2, -3, -4)
With tbl
.Cell(1, 1).Range.Text = "test"
For I = LBound(ListeBordures) To UBound(ListeBordures)
With .Borders(ListeBordures(I))
.LineStyle = wdLineStyleDot
.LineWidth = wdLineWidth100pt
End With
Next I
End With
End With
Set tbl = Nothing: Set word_fichier = Nothing: Set word_app = Nothing
End Sub
经过几个小时的研究,我发现了这些行:
Sub test()
'Déclaration des variables
Dim I As Integer
Dim Fichier As String
Dim MaFeuille As Worksheet
Dim ListeBordures As Variant
Dim word_app As Word.Application, word_fichier As Word.Document, tbl As Word.Table, rngCell As Word.Range
'On récupère le fichier test
Fichier = ActiveWorkbook.Path & "\" & "test.docx"
'Ouverture de word
Set word_app = CreateObject("Word.Application")
With word_app
.Visible = True
.WindowState = 1
Set word_fichier = .Documents.Open(Fichier)
End With
'Test tableau bas de page
With word_fichier
Set tbl = .Tables.Add(.Sections(1).Footers(wdHeaderFooterPrimary).Range, 1, 1, wdWord8TableBehavior)
ListeBordures = Array(-1, -2, -3, -4)
With tbl
.Cell(1, 1).Range.Text = "test"
.Rows.HorizontalPosition = InchesToPoints(1)
.Rows.VerticalPosition = InchesToPoints(-2)
.Columns(1).SetWidth ColumnWidth:=310.7, RulerStyle:=1
For I = LBound(ListeBordures) To UBound(ListeBordures)
With .Borders(ListeBordures(I))
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth225pt
.Color = RGB(255, 0, 0)
End With
Next I
End With
End With
Set tbl = Nothing: Set word_fichier = Nothing: Set word_app = Nothing
End Sub
用 .Rows.HorizontalPosition = InchesToPoints(1)
和.Rows.VerticalPosition = InchesToPoints(-2)
进行定位
和 .Columns(1).SetWidth ColumnWidth:=310.7, RulerStyle:=1
尺码
我需要使用 excel vba 在 .docx 的页脚中创建一个 table。我有我的手机,但你知道是否有任何方法可以改变它的大小和位置?谢谢
编辑:我发现了这个:https://docs.microsoft.com/en-us/office/vba/api/word.tables.add
但是我不知道在 DefaultTableBehavior 和 AutoFitBehavior 中放什么
Option Explicit
Sub test()
'Déclaration des variables
Dim I As Integer
Dim Fichier As String
Dim MaFeuille As Worksheet
Dim ListeBordures As Variant
Dim word_app As Word.Application, word_fichier As Word.Document, tbl As Word.Table, rngCell As Word.Range
'On récupère le fichier test
Fichier = ActiveWorkbook.Path & "\" & "test.docx"
'Ouverture de word
Set word_app = CreateObject("Word.Application")
With word_app
.Visible = True
.WindowState = 1
Set word_fichier = .Documents.Open(Fichier)
End With
'Test tableau bas de page
With word_fichier
Set tbl = .Tables.Add(.Sections(1).Footers(wdHeaderFooterPrimary).Range, 1, 1)
ListeBordures = Array(-1, -2, -3, -4)
With tbl
.Cell(1, 1).Range.Text = "test"
For I = LBound(ListeBordures) To UBound(ListeBordures)
With .Borders(ListeBordures(I))
.LineStyle = wdLineStyleDot
.LineWidth = wdLineWidth100pt
End With
Next I
End With
End With
Set tbl = Nothing: Set word_fichier = Nothing: Set word_app = Nothing
End Sub
经过几个小时的研究,我发现了这些行:
Sub test()
'Déclaration des variables
Dim I As Integer
Dim Fichier As String
Dim MaFeuille As Worksheet
Dim ListeBordures As Variant
Dim word_app As Word.Application, word_fichier As Word.Document, tbl As Word.Table, rngCell As Word.Range
'On récupère le fichier test
Fichier = ActiveWorkbook.Path & "\" & "test.docx"
'Ouverture de word
Set word_app = CreateObject("Word.Application")
With word_app
.Visible = True
.WindowState = 1
Set word_fichier = .Documents.Open(Fichier)
End With
'Test tableau bas de page
With word_fichier
Set tbl = .Tables.Add(.Sections(1).Footers(wdHeaderFooterPrimary).Range, 1, 1, wdWord8TableBehavior)
ListeBordures = Array(-1, -2, -3, -4)
With tbl
.Cell(1, 1).Range.Text = "test"
.Rows.HorizontalPosition = InchesToPoints(1)
.Rows.VerticalPosition = InchesToPoints(-2)
.Columns(1).SetWidth ColumnWidth:=310.7, RulerStyle:=1
For I = LBound(ListeBordures) To UBound(ListeBordures)
With .Borders(ListeBordures(I))
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth225pt
.Color = RGB(255, 0, 0)
End With
Next I
End With
End With
Set tbl = Nothing: Set word_fichier = Nothing: Set word_app = Nothing
End Sub
用 .Rows.HorizontalPosition = InchesToPoints(1)
和.Rows.VerticalPosition = InchesToPoints(-2)
进行定位
和 .Columns(1).SetWidth ColumnWidth:=310.7, RulerStyle:=1
尺码