用VBA /macros打开一个工作簿是只读吗?

我想我的代码打开一个工作簿(总是相同的),检测到第一个空行,只写入该行中的两个单元格,然后保存/closures工作簿。 这似乎是一个简单的问题,但macros似乎打开该文件的副本,然后locking它进行编辑。

你能看到我的开放代码中的任何错误? 我知道该文件打开,行search工作,但它然后1.不写入单元格,并2.locking文件。

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

你是否需要打开一个新的Excel应用程序来打开一个工作簿?

你不能只是做这样的事情:

 Sub Macro1() Dim wkb As Workbook Workbooks.Open Filename:="\User Documents$\bob\My Documents\workbook_open_example.xlsx" Set wkb = Workbooks("workbook_open_example.xlsx") End Sub