- VB,VBA
-
2016-11-28 - 更新:2021-01-13
AccessからExcelを操作し、罫線等を設定する場合、私自身もいつも定数の値が何だったかいちいち調べているので、備忘録も兼ねて書いておきます。
まずは全体の流れ
1 | Dim ws |
2 |
3 | Dim xlApp As Object |
4 | Dim xlBook As Object |
5 | Dim xlSheet As Object |
6 | Dim FileName As String |
7 |
8 | Set ws = CreateObject( "WScript.Shell" ) |
9 |
10 | FileName = ws.SpecialFolders( "Desktop" ) & "\雛形.xlsx" |
11 |
12 | Set xlApp = CreateObject( "Excel.Application" ) |
13 | Set xlBook = xlApp.Workbooks.Open(FileName) |
14 | Set xlSheet = xlBook.WorkSheets(1) |
15 |
16 | With xlSheet |
17 | 'このブロック内に書いていきます |
18 | End With |
19 |
20 | '保存 |
21 | xlBook.Save |
22 |
23 | xlBook.Close |
24 |
25 | xlApp.Application.Quit |
26 |
27 | Set xlSheet = Nothing |
28 | Set xlBook = Nothing |
29 | Set xlApp = Nothing |
罫線を引く
1 | .Range( "A1:I1" ).Borders.LineStyle = 1 |
2 | .Range( "A1:I1" ).Borders(8).LineStyle = -4118 |
3 | .Range( "A1:I1" ).Borders(11).LineStyle = -4115 |
4 | .Range( "A1:I1" ).Borders(11).Weight = 1 |
