Private Sub LIST_Clear() Dim wb As Excel.Workbook Dim sh As Excel.Worksheet Dim LastRow As Integer Try wb = GetObject(ListFile) Catch ex As Exception
MessageBox.Show(ex.Message)
End Try sh = wb.Sheets(“Sheet1”) LastRow = sh.Cells(sh.Rows.Count, 1).end(Excel.XlDirection.xlUp).row Dim tl = sh.Cells(2, 1) Dim br = sh.Cells(LastRow + 1, 7) Dim wrange = sh.Range(tl, br) wrange.ClearContents() wb.Save() ←ここでExcelブックが壊れる(シートが参照できなくなります) wb.Close() End Sub
If IO.File.Exists(ListFile) = True Then Try System.IO.File.Move(ListFile, ListFile) Catch ex As Exception '移動できなかったら起動していると判定 GoTo ExcelOpen End Try End If ''ファイルオープン wb = Appxl.Workbooks.Open(ListFile) GoTo ExcelOpenExit ExcelOpen: Try wb = GetObject(ListFile) Catch ex As Exception
MessageBox.Show(ex.Message) End Try ExcelOpenExit: