[英]Range issue in Access/excel vba
不確定我在做什么錯。 以下所有語句均不會產生錯誤,但是它們無法正常工作。 之前我有一個關於邊界的問題,我以為它有用,但沒有
這是代碼片段
With ws
With .Range(.Cells(startRow, startCol), .Cells(endRow, endCol))
.Borders.LineStyle = 1
.Borders.Weight = 4
End With
End With
ws.Range("D1").Value = 3.14159
With ws.Range("D1").Borders(9)
.LineStyle = 1
.Weight = 2
.ColorIndex = 3
End With
ws.usedrange.Borders.LineStyle = 1
ws.usedrange.Borders.Weight = 4
ws.usedrange.Borders.Color = RGB(255, 0, 0)
With ws.Range("E1:F2")
.Value = "x"
.Font.Bold = True
.Borders.LineStyle = 1
End With
可能是您的參數.............以下作品:
Sub dural()
Dim ws As Worksheet
Set ws = ActiveSheet
startRow = 3
startCol = 3
endRow = 7
endCol = 7
With ws
With .Range(.Cells(startRow, startCol), .Cells(endRow, endCol))
.Borders.LineStyle = 1
.Borders.Weight = 4
End With
End With
End Sub
我從上一個問題中獲取了您的代碼,並添加了最后四行以保存更改並關閉wb。 這應該可以解決您的問題:
Sub setBorder()
Dim xlApp As Object
Dim wb As Object
Dim ws As Object
Dim rng As Object
Dim startRow As Integer, startCol As Integer
Dim endRow As Integer, endCol As Integer
Set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False
Set wb = xlApp.Workbooks.Open("H:\Documents\Misc-Work\BU\test.xlsx")
'your code
wb.Close True
xlApp.Quit
Set wb = Nothing
Set xlApp = Nothing
End Sub
請注意,由於您已經運行了之前的代碼(沒有關閉wb和xlApp),可能您需要使用任務管理器關閉文件“ H:\\ Documents \\ Misc-Work \\ BU \\ test.xlsx”(即使看起來像您尚未打開此文件)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.