VBA 快速实现Word三线表

Sub TablLine3()
    ' 三线表格式设置
    Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
 
    
    Options.DefaultBorderLineWidth = wdLineWidth100pt
    With Selection.Borders(wdBorderTop)
        .LineStyle = Options.DefaultBorderLineStyle
        .LineWidth = Options.DefaultBorderLineWidth
        .Color = Options.DefaultBorderColor
    End With
    Options.DefaultBorderLineWidth = wdLineWidth100pt
    With Selection.Borders(wdBorderBottom)
        .LineStyle = Options.DefaultBorderLineStyle
        .LineWidth = Options.DefaultBorderLineWidth
        .Color = Options.DefaultBorderColor
    End With
    
    Options.DefaultBorderLineWidth = wdLineWidth025pt
    With Selection.Rows(1).Borders(wdBorderBottom) '第一行的底边框
        .LineStyle = Options.DefaultBorderLineStyle
        .LineWidth = Options.DefaultBorderLineWidth
        .Color = Options.DefaultBorderColor
    End With
    
End Sub

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
如果要在Excel中使用VBA代码实现多表关联,可以尝试以下步骤: 1. 打开Excel文件,按下Alt+F11打开VBA编辑器。 2. 在VBA编辑器中,选择Insert -> Module,创建一个新的模块。 3. 在新模块中添加以下代码: ``` Sub MultiTableJoin() Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet Dim i As Long, j As Long, k As Long Dim lRow1 As Long, lRow2 As Long Dim vArray1 As Variant, vArray2 As Variant, vArray3 As Variant Dim dIndex As Object '设置要关联的两个表 Set ws1 = ThisWorkbook.Sheets("Sheet1") '表1 Set ws2 = ThisWorkbook.Sheets("Sheet2") '表2 '获取表1和表2的数据范围 lRow1 = ws1.Range("A1").End(xlDown).Row lRow2 = ws2.Range("A1").End(xlDown).Row '将表1和表2的数据读入到数组中 vArray1 = ws1.Range("A1").Resize(lRow1, 2).Value vArray2 = ws2.Range("A1").Resize(lRow2, 2).Value '创建一个字典对象,用于存储关联后的数据 Set dIndex = CreateObject("Scripting.Dictionary") '将表1和表2的数据进行关联 For i = 1 To lRow1 For j = 1 To lRow2 If vArray1(i, 1) = vArray2(j, 1) Then dIndex.Item(vArray1(i, 1)) = dIndex.Item(vArray1(i, 1)) & "," & vArray2(j, 2) End If Next j Next i '将关联后的数据填充到另一个表中 Set ws3 = ThisWorkbook.Sheets.Add '创建一个新表 ws3.Name = "Result" '将新表命名为Result vArray3 = dIndex.Items k = 1 For i = 0 To dIndex.Count - 1 vArray3(i) = Mid(vArray3(i), 2) '去掉第一个逗号 vArray3(i) = Split(vArray3(i), ",") '将数据转换为数组 For j = 0 To UBound(vArray3(i)) k = k + 1 ws3.Cells(k, 1) = dIndex.Keys()(i) ws3.Cells(k, 2) = vArray3(i)(j) Next j Next i '删除原始数据 ws1.Range("A1").Resize(lRow1, 2).ClearContents ws2.Range("A1").Resize(lRow2, 2).ClearContents End Sub ``` 4. 在Excel中准备两个需要关联的表,然后运行上面的代码即可。 该代码将选定的两个表中的共同列进行关联,并将结果输出到一个新的表中。要修改输入和输出的表,请更改代码中的“Sheet1”、“Sheet2”和“Result”。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值