2012-01-06 4 views
0

Access 데이터베이스에 연결하고 몇 가지 SQL 문을 만든 다음 결과를 Excel 파일에 쓰려고하는 Visual Basic 프로그램을 작성했습니다.Visual Basic (VBA 아님) Visual Basic 대화 상자 가져 오기

모든는 다른 이름으로 저장 대화 상자를 호출 할 때를 제외하고, 제대로 작동 :

xlApp.Dialogs(Excel.XlBuiltInDialog.xlDialogSaveAs).Show() 

대화 최대화하는 프로그램, 뒤에있다. 따라서 프로그램이 대화 상자가 닫힐 때까지 기다리지 만 대화 상자에 액세스 할 수 없습니다 (Alt + Tab을 제외하고는 추악한 해결 방법입니다).

대화 상자를 앞쪽으로 밀어 넣을 방법이 있습니까? 나는 관련된 스레드 here을 발견했다. 그러나 나는 분리 된 스레드를 다루지 않는다. 거기에있는 OP는 BringToFront 메서드를 제안하지만 xlApp.Dialogs와 함께 사용하는 방법은 잘 모르겠습니다.

미리 도움을 청하십시오!

Dim saveAsHwnd as Long 

call saveAsHwnd = FindWindowByPartialTitle("Save") 
call SetForegroundWindo(saveAsHwnd) 

뿐만 아니라 SetForegroundWindow를 decalre하는 것을 잊지 마세요 :

답변

0

당신이 뭔가를 할 수 있어야 창 핸들을 찾아 위의 기능 그래서 SetForegroundWindow

Public Function FindWindowByPartialTitle(ByVal _ 
    TestFlex_string As String) As Long 
    m_TestFlexString = TestFlex_string 
    m_TestFlexHwnd = 0 

    ' Enumerate windows. 
    EnumWindows AddressOf EnumCallback, 0 

    ' Return the hWnd found (if any). 
    FindWindowByPartialTitle = m_TestFlexHwnd 
End Function 

' Check a returned task to see if it's the one we want. 
Public Function EnumCallback(ByVal app_hWnd As Long, ByVal _ 
    param As Long) As Long 
Dim buf As String 
Dim title As String 
Dim Length As Long 

    ' Get the window's title. 
    Length = GetWindowTextLength(app_hWnd) 
    buf = Space$(Length) 
    Length = GetWindowText(app_hWnd, buf, Length) 
    title = Left$(buf, Length) 

    ' See if the title contains the TestFlex string. 
    If InStr(title, m_TestFlexString) <> 0 Then 
     ' This is the one we want. 
     m_TestFlexHwnd = app_hWnd 

     ' Stop searching. 
     EnumCallback = 0 
    Else 
     ' Continue searching. 
     EnumCallback = 1 
    End If 
End Function 

전화

Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long