MSACCESS VBA:将边框添加到Excel工作表 [英] MSACCESS VBA: Add borders to Excel Sheet

查看:79
本文介绍了MSACCESS VBA:将边框添加到Excel工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下内容无效.如何添加边框?谢谢!

The below does not work. How do I add borders? Thanks!

            Set objApp = CreateObject("Excel.Application")
            objApp.Visible = True
            Set wb = objApp.Workbooks.Open("aFile.xls", True, False)
            objApp.Cells.Select
            objApp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
            objApp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
            With objApp.Selection.Borders(xlEdgeLeft)
                .LineStyle = xlContinuous
                .ColorIndex = 0
                .TintAndShade = 0
                .Weight = xlThin
            End With
            With objApp.Selection.Borders(xlEdgeTop)
                .LineStyle = xlContinuous
                .ColorIndex = 0
                .TintAndShade = 0
                .Weight = xlThin
            End With
            With objApp.Selection.Borders(xlEdgeBottom)
                .LineStyle = xlContinuous
                .ColorIndex = 0
                .TintAndShade = 0
                .Weight = xlThin
            End With
            With objApp.Selection.Borders(xlEdgeRight)
                .LineStyle = xlContinuous
                .ColorIndex = 0
                .TintAndShade = 0
                .Weight = xlThin
            End With
            With objApp.Selection.Borders(xlInsideVertical)
                .LineStyle = xlContinuous
                .ColorIndex = 0
                .TintAndShade = 0
                .Weight = xlThin
            End With
            With objApp.Selection.Borders(xlInsideHorizontal)
                .LineStyle = xlContinuous
                .ColorIndex = 0
                .TintAndShade = 0
                .Weight = xlThin
            End With

            Set objApp = Nothing

推荐答案

VBA代码对我不起作用,因此我找到了解决方法.由于我使用的是Excel模板来创建Excel工作表.我修改了Excel模板以打印网格线.

The VBA code did not work for me so I discovered a workaround. Since I was using an Excel template to create the Excel sheet. I modified the Excel template to print Gridlines.

要启用网格线进行打印,请执行以下操作:

To enable Gridlines to Print:

Excel>打印预览>页面设置>图纸>在打印下选中标记网格线.

Excel > Print Preview > Page Setup > Sheet > Check mark gridlines under Print.

这篇关于MSACCESS VBA:将边框添加到Excel工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆