문제

작성되었습 VBA 매크로 여는 HTML 문서에서 Excel(수행하기 위해 다양한에서 계산합니다.)Excel 검색에 대한 HTML 문서에는 현재 폴더에 있습니다.면 그것은 그것을 찾을 수 없습니다 거기에는 그것이 생산하는 파일 열기 상자는 사용자의 위치를 찾은 HTML 문서를 수 있습니다.모든 좋은 지금까지.그러나 한 사용자는 선택을 취소(보다는 오히려를 선택하면 파일),나는 원하는 Excel 메시지를 표시하고 종료한다.

메시지를 생성하지만 코드를 중지와 함께 다음과 같은 오류가:

런타임 오류'424':객체를 필요합니다.

이처럼 들리지 않는데 너무 많이 해야만 했으로 실행되는 하나의 벽돌 벽 후 다른 노력하고 네일은 무엇이 문제를 일으킬 수 있습니다.

하위는 단지 작동하지 않는 것입니다:

Sub ExitWithoutPrompt()

MsgBox "You failed to select a file, therefore Excel will now close.  Please refer to the readme file."
Excel.Application.DisplayAlerts = False
Excel.Application.Quit

End Sub

내가 사용하 MS Excel2002,그러나 나는 치열한 솔루션에 대한 작업으로 많은 변종의 엑셀로 가능합니다.

어떤 도움을 기꺼이 받으로 나가 어디가 잘못입니다.난 완전한 신참여 방법,그래서 가능한 모든 경우에십시오 장황한 모든 지침이 있다.

으로 사용 될 수 있습은 아래에 포함(를 만드는 위험에서 이 게시물을 다루기 힘드)는 다른 두 개의 잠수함 내가 사용하는 매크로에서 사용:

첫째는 하위:

Sub Endurance()

Call OpenHTML

Range("G27").Value = "Category"
Range("G28").Value = "Meat"
Range("G29").Value = "Veg"
Range("G30").Value = "PRP"
Range("F27").Value = "Fleet"
Range("E27").Value = "Consumption"

Range("E32").Value = "Endurance"

Range("E33").Value = "Lowest Category"
Range("E34").Value = "Fleet"
Range("E35").Value = "Consumption"

Range("E27, F27, G27, E32").Font.Bold = True
Range("F28").Value = WorksheetFunction.Sum(Range("E8,E9,E11,E14,E21"))
Range("E28").Value = WorksheetFunction.Sum(Range("G8,G9,G11,G14,G21"))
Range("F29").Value = WorksheetFunction.Sum(Range("E10,E16"))
Range("E29").Value = WorksheetFunction.Sum(Range("G10,G16"))
Range("F30").Value = WorksheetFunction.Sum(Range("E20,E22"))
Range("E30").Value = WorksheetFunction.Sum(Range("G20,G22"))

Columns("E:F").EntireColumn.AutoFit

Range("G28:G30, E27, F27, G27, G33").Select
    With Selection
        .HorizontalAlignment = xlRight
    End With

Range("E27:G30, E32:G35").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone


Dim Endurance As Double
Endurance = WorksheetFunction.Min(Range("F28:F30"))
Range("G34").Value = WorksheetFunction.RoundDown(Endurance, 0)

Endurance = WorksheetFunction.Min(Range("E28:E30"))
Range("G35").Value = WorksheetFunction.RoundDown(Endurance, 0)

Range("G33").Value = Endurance

Dim LowCat As String

LowCat = WorksheetFunction.VLookup(Endurance, Range("E28:G30"), 3, False)
Range("G33").Value = LowCat

ActiveSheet.PageSetup.PrintArea = "$A$1:$G$35"
ActiveSheet.PageSetup.Orientation = xlLandscape

Range("G36").Select

If MsgBox("Print endurance statement?", vbYesNo + vbDefaultButton2, "Print endurance") = vbYes Then
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    Else
    Range("G36").Select
    End If


End Sub

그리고 두 번째는 하위:

Sub OpenHTML()

On Error GoTo MissingFile

Workbooks.Open FileName:=ThisWorkbook.Path & "\TRICAT Endurance Summary.html"


Exit Sub

MissingFile:

Dim Finfo As String
Dim FilterIndex As Integer
Dim Title As String
Dim FileName As Variant

' Set up list of file filters
Finfo = "HTML Files (*.html),*.html," & _
        "All Files (*.*),*.*,"

' Display *.html by default
    FilterIndex = 1

' Set the dialog box caption
Title = "Select TRICAT Endurance Summary"

' Get the filename
FileName = Application.GetOpenFilename(FInfor, FilterIndex, Title)

' Handle Return info from dialog box
If FileName = False Then
    Call ExitWithoutPrompt
    Else
    MsgBox "You selected" & FileName
    Workbooks.Open FileName

End If

End Sub

만약 당신이 지금까지,읽기를 위한 감사합니다....

도움이 되었습니까?

해결책

호출을 추가 ActiveWorkbook.Close 하기 ExitWithoutPrompt:

Sub ExitWithoutPrompt()
    MsgBox "You failed to select a file, therefore Excel will now close.  Please refer to the readme file."
    Excel.Application.DisplayAlerts = False
    Excel.Application.Quit
    ActiveWorkbook.Close False
End Sub

이것이 나를 위해서 Excel2003.

어떤 이유로,의 순서화 Application.QuitActiveWorkbook.Close 은 중요합니다.카운터-직관적으로,적어도 나에게 전화하는 경우 ActiveWorkbook.CloseApplication.Quit 당신은 아직도 오류가 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top