我希望我的代码打开一个工作簿(总是同一个),检测第一个空闲行,只写入该行中的两个单元格,然后保存/关闭工作簿。这似乎是一个简单的问题,但宏似乎正在打开文件的副本,然后将其锁定以进行编辑。
你能在我的开放代码中看到任何错误吗?我知道文件打开并且行搜索有效,但是它 1. 从不写入单元格,并且 2. 锁定文件。
Function WriteToMaster(Num, Path) As Boolean
'Declare variables
Dim xlApp As Excel.Application
Dim wb As Workbook
Dim ws As Worksheet
Dim infoLoc As Long
Set xlApp = New Excel.Application
'Specifies where the Master Move Key is stored
Set wb = xlApp.Workbooks.Open("DOC LOCATION")
Set ws = wb.Worksheets("Sheet1")
'Loop through cells, looking for an empty one, and set that to the loan number
infoLoc = firstBlankRow(ws)
MsgBox "First blank row is " & infoLoc & ". Num is " & Num
ws.Cells(infoLoc, 1).Value = Num
ws.Cells(infoLoc, 2).Value = Path
'Save, close, and quit
wb.Save
wb.Close
xlApp.Quit
'Resets the variables
Set ws = Nothing
Set wb = Nothing
Set xlApp = Nothing
'pieces of function from http://p2p.wrox.com/vb-how/30-read-write-excel-file-using-vb6.html
End Function
再次感谢你,stackoverflow <3