office交流网--QQ交流群号

Access培训群:792054000         Excel免费交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

Access中对Excel文件设置字体格式

2021-01-07 08:00:00
tmtony8
原创
7468

access 除了把数据导出到Excel中,还需要对导出的数据设置一定的字体格式。

比如设置表头格式,这样能更加醒目地看出表格的内容。

如这里先对所有已使用的单元格设置格式,再对表头设置格式(字号14,字体微软雅黑,加粗,颜色变深)

 Dim xlWbk As Excel.Workbook
    Dim xlWsh As Excel.Worksheet
    Set xlApp = GetObject(, "Excel.Application")
    xlApp.Visible = True
    Set xlWbk = xlApp.Workbooks.Open(CurrentProject.Path & "\示例1.xlsx")
    Set xlWsh = xlWbk.Worksheets(1)
    xlWsh.Activate
    
    With xlWsh.UsedRange     '设置已使用的单元格区域格式
        .Font.Name = "Times New Roman "
        .Font.Size = 10
    End With
    
    With xlWsh.Range("1:1")    '设置第一行的单元格区域格式
        .Font.Size = 14
        .Font.Name = "微软雅黑"
        .Font.Bold = True
        .Font.TintAndShade = True
    End With
    
    Set xlWsh = Nothing
    Set xlWbk = Nothing
    Set xlApp = Nothing

设置效果如图:

    分享