I wrote a code last night and will prepare some of the worksheet in Excel (the same name "Sheet2") batch. After successful deletion, I found that the strange problem was found. After the deleted Excel file was opened and found out. No, a worksheet is not, but with the VB editor, it is found that the worksheet is still, but there is no way to display.
Private Sub CommandButton1_Click () Dim app As Excel.ApplicationDim xlapp As VariantDim xlworkbooks As WorkbooksDim MyFile, MyPath, MyNameMyPath = "d: / temp" MyName = Dir (MyPath & "/" & "* .xls") Do While MyName <> "" 'Start loop.
Set xlapp = GetObject (MyPath & "/" & MyName) Set w_sheets = xlapp.Worksheets xlapp.Application.DisplayAlerts = False 'without warning xlapp.Worksheets ( "sheet2"). Delete Workbooks (MyName) .Save xlapp.Application. Displayalerts = true xlapp.application.visible = true workbooks (myname) .close myname = dir 'looks for the next directory. Loopend Sub
Later, then discussed debugging with the master, find that if you don't have to getObject, it can reach normal with Workbook.Open first.
Application.workbooks.open myname 'This is a key, first open the worksheet, anything, why do you say the above situation I can't clearly, but you can solve the problem. . . Ha ha