Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
I am using the followig code. The thing is that excel won't stop. It is something related to For...Next. If I remove For...Next then everything is ok. What could be wrong? On Error GoTo ErrorHandler Dim MyXLApp As New Excel.Application Application.DisplayAlerts = False Dim strSheetName As String strSheetName = "INFORMATION" MyXLApp.Workbooks.Open FileName:="C:\yyy\1_08A.xls" If MyXLApp.Worksheets.Count = 1 Then MyXLApp.Worksheets.Add.Name = "DELETE" MyXLApp.Workbooks.Application.SaveWorkspace End If If MyXLApp.Worksheets.Count 1 Then For buc_sheets = 1 To MyXLApp.Worksheets.Count den_sheet = Worksheets(buc_sheets).Name If strSheetName = den_sheet Then MyXLApp.Worksheets(den_sheet) Then MyXLApp.Worksheets(strSheetName).Activate MyXLApp.Worksheets(strSheetName).Delete End If Next End If GoTo line100 MyXLApp.Workbooks.Application.SaveWorkspace line100: MyXLApp.Workbooks.Application.SaveWorkspace MyXLApp.Workbooks.Close Application.DisplayAlerts = True MyXLApp.Application.Quit Set MyXLApp = Nothing ErrorHandler: Select Case Err.Number Case 9 MsgBox Err.Description End Select |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Not tried it, but it may be because you are using auto-instancing..
Instead of this Dim MyXLApp As New Excel.Application Try Dim MyXLApp As Excel.Application Set MyXLApp = New Excel.Application -- HTH Bob Phillips (replace somewhere in email address with gmail if mailing direct) "alexia_net" wrote in message oups.com... Hi I am using the followig code. The thing is that excel won't stop. It is something related to For...Next. If I remove For...Next then everything is ok. What could be wrong? On Error GoTo ErrorHandler Dim MyXLApp As New Excel.Application Application.DisplayAlerts = False Dim strSheetName As String strSheetName = "INFORMATION" MyXLApp.Workbooks.Open FileName:="C:\yyy\1_08A.xls" If MyXLApp.Worksheets.Count = 1 Then MyXLApp.Worksheets.Add.Name = "DELETE" MyXLApp.Workbooks.Application.SaveWorkspace End If If MyXLApp.Worksheets.Count 1 Then For buc_sheets = 1 To MyXLApp.Worksheets.Count den_sheet = Worksheets(buc_sheets).Name If strSheetName = den_sheet Then MyXLApp.Worksheets(den_sheet) Then MyXLApp.Worksheets(strSheetName).Activate MyXLApp.Worksheets(strSheetName).Delete End If Next End If GoTo line100 MyXLApp.Workbooks.Application.SaveWorkspace line100: MyXLApp.Workbooks.Application.SaveWorkspace MyXLApp.Workbooks.Close Application.DisplayAlerts = True MyXLApp.Application.Quit Set MyXLApp = Nothing ErrorHandler: Select Case Err.Number Case 9 MsgBox Err.Description End Select |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Is Visual Basic the same as Visual Studio 2008? | Excel Worksheet Functions | |||
Can I run Visual Basic procedure using Excel Visual Basic editor? | Excel Programming | |||
changing the visual basic in office 2003 to visual studio net | Excel Discussion (Misc queries) | |||
Excel/Visual Basic | Excel Programming | |||
Visual Basic within Excel | Excel Programming |