Open and Close another Workbook from VBA
- Do you need another instance of Excel ?
Set srcApp = New Excel.Application
Just open all in your current instance.
- Also, it would us (and you) if you declared your variables
Dim srcWkBk as workbook
Check out "Option Explicit" in the VBA help.
- Also, I doubt you are opening the file you think. You pass "src" as an
argument, but open "myFile", whatever that is.
Sub CleanSrc(src As String)
.......
Set srcWkBk = srcApp.Workbooks.Open(myFile)
- Remove the ( ) from
srcWkBk.Close (True)
NickHK
"Charles in Iraq" wrote in message
...
Greetings.
I wrote the following subroutine to open, do some formatting,
and then close a workbook prior to importing its data into my
current workbook:
Sub CleanSrc(src As String)
Set srcApp = New Excel.Application
srcApp.Visible = False
Set srcWkBk = srcApp.Workbooks.Open(myFile)
Set srcSht = srcWkBk.Sheets(1)
srcLast = srcSht.Range("A1").End(xlDown).Row
srcSht.Rows((srcLast + 1) & ":" & (srcLast + 5)).Delete
srcWkBk.Close (True)
Set srcWkBk = Nothing
Set srcApp = Nothing
End Sub
My problem is that later when I attempt to import data from
this workbook, I get complaints it being locked (by myself!)
and read only.
It appears that somehow this workbook is never really closed
and/or the application I spun up wasn't exited properly.
Can somebody please tell me what I can do to fix this problem?
Regards,
Charles
|