powered by simpleCommunicator - 2.0.39     © 2025 Programmizd 02
Форумы / Microsoft Office [игнор отключен] [закрыт для гостей] / поиск в макросах в нескольких файлах
21 сообщений из 21, страница 1 из 1
поиск в макросах в нескольких файлах
    #39170644
andreymx
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Есть несколько (много) файлов excel (xls xlsm) с макросами. Запаролены, но пароли известны.
Каким скриптом (bat cmd vba vbs excel delphi c# и т.д.) можно в них найти подстроку и вывести строку, куда эта подстрока входит?
...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39170660
Фотография Shocker.Pro
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
А что конкретно вызывает вопросы? Ты ж вроде умеешь писать на VBA...
...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39170674
andreymx
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Shocker.ProА что конкретно вызывает вопросы? Ты ж вроде умеешь писать на VBA...нашел что-то вот такое как основу
Код: vbnet
1.
2.
3.
For i = 1 To ActiveWorkbook.VBProject.VBComponents.Count
    ActiveWorkbook.VBProject.VBComponents(i).Export ThisWorkbook.FullName & "_" & i & ".bas"
Next

так можно экспортировать, потом просмотреть файловым поиском

пока не в курсе, как пробегаться по файлам и задавать пароль
...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39170678
andreymx
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
открыть-то могу, как пароль в проджекте задать? без него гавкает
Код: vbnet
1.
2.
3.
4.
     Workbooks.Open Filename:="D:\Пользователи\user\Мои документы\test.xlsm"
    MsgBox ActiveWorkbook.VBProject.Protection // выводит 1
    
    For i = 1 To ActiveWorkbook.VBProject.VBComponents.Count //здесь ругается, что проект защищён 
...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39170690
andreymx
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
порылся в нетях
Такое ощущение, что только всякими хаками вроде этого
А напрямую запрещено
...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39171215
andreymx
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Если у кого есть идеи насчет чтения текстов запароленных макросов, прошу поделиться.
Пароль известен, ломать не надо!
...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39171272
Фотография The_Prist
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
andreymx,

Без распароливания проекта не получится. Иначе зачем же вообще пароль тогда? :)
...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39171277
andreymx
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
The_Prist,

ну пароль-то я знаю, это мой прожект
...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39171281
andreymx
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Открываю из проекта, где тот же самый пароль - нифига.
...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39171304
Фотография The_Prist
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
andreymx,

я здесь выкладывал код: http://www.excel-vba.ru/chto-umeet-excel/kak-programmno-snyat-parol-s-vba-proekta/
он мало отличается от приведенного выше. Тоже нестабилен. Все руки не доходят сделать с применением API, хотя это тоже можно сделать - чуть проблемнее. Я уже делал такое, правда, не из VBA.
...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39171308
andreymx
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
The_Prist,

через OLE объекты?
...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39171796
Фотография The_Prist
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
andreymx,

не совсем понял. Причем здесь OLE? Я же написал - API. Поиск нужных окон, посыл нужных сообщений в нужные поля и нажатия кнопок.
...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39171800
andreymx
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Не из vba - это как?
...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39171904
KL (XL)
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Вот такая халтурная адаптация когда-то найденного кода. Мелькает сильно. У меня в MSO2013 исходный код ( http://www.siddharthrout.com/2013/04/24/unprotecting-vba-project-password-using-a-password-that-you-know/#!prettyPhoto ) все время терял окна, т.ч. приходится постоянно активировать проект. К тому же пришлось доработать, чтобы закрывалось окно свойств проекта. Вроде срабатывает стабильно, но надо учитывать еще и язык MSO (названия окон), а также то, что имя проекта может быть изменено. В общем не ахти какой универсальный код:

Код: vbnet
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Private Declare Function GetWindowTextLength Lib "user32" Alias _
"GetWindowTextLengthA" (ByVal hWnd As Long) As Long

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Dim Ret As Long, ChildRet As Long, OpenRet As Long, PropRet As Long
Dim strBuff As String, ButCap As String

Const WM_SETTEXT = &HC
Const BM_CLICK = &HF5

Const MyPassword As String = "test"
Const MyProjName As String = "VBAProject"
Const MyWbPath As String = "G:\Test\Test.xlsm"
Const MyModule As String = "Module1"

Sub UnlockVBA()
    Dim xlAp As Object, oWb As Object
    
    Set xlAp = CreateObject("Excel.Application")

    xlAp.Visible = True

    '~~> Open the workbook in a separate instance
    Set oWb = xlAp.Workbooks.Open(MyWbPath)

    '~~> Launch the VBA Project Password window
    '~~> I am assuming that it is protected. If not then
    '~~> put a check here.
    xlAp.VBE.MainWindow.SetFocus
    xlAp.VBE.CommandBars(1).FindControl(ID:=2578, recursive:=True).Execute
    '~~> Get the handle of the "VBAProject Password" Window
    xlAp.VBE.MainWindow.SetFocus
    Ret = FindWindow(vbNullString, MyProjName & " Password")

    If Ret <> 0 Then
        'MsgBox "VBAProject Password Window Found"

        '~~> Get the handle of the TextBox Window where we need to type the password
        xlAp.VBE.MainWindow.SetFocus
        ChildRet = FindWindowEx(Ret, ByVal 0&, "Edit", vbNullString)

        If ChildRet <> 0 Then
            'MsgBox "TextBox's Window Found"
            '~~> This is where we send the password to the Text Window
            SendMess MyPassword, ChildRet

            DoEvents

            '~~> Get the handle of the Button's "Window"
            xlAp.VBE.MainWindow.SetFocus
            ChildRet = FindWindowEx(Ret, ByVal 0&, "Button", vbNullString)

            '~~> Check if we found it or not
            If ChildRet <> 0 Then
                'MsgBox "Button's Window Found"

                '~~> Get the caption of the child window
                strBuff = String(GetWindowTextLength(ChildRet) + 1, Chr$(0))
                GetWindowText ChildRet, strBuff, Len(strBuff)
                ButCap = strBuff

                '~~> Loop through all child windows
                Do While ChildRet <> 0
                    '~~> Check if the caption has the word "OK"
                    If InStr(1, ButCap, "OK") Then
                        '~~> If this is the button we are looking for then exit
                        OpenRet = ChildRet
                        Exit Do
                    End If

                    '~~> Get the handle of the next child window
                    xlAp.VBE.MainWindow.SetFocus
                    ChildRet = FindWindowEx(Ret, ChildRet, "Button", vbNullString)
                    '~~> Get the caption of the child window
                    strBuff = String(GetWindowTextLength(ChildRet) + 1, Chr$(0))
                    GetWindowText ChildRet, strBuff, Len(strBuff)
                    ButCap = strBuff
                Loop

                '~~> Check if we found it or not
                If OpenRet <> 0 Then
                    '~~> Click the OK Button
                    SendMessage ChildRet, BM_CLICK, 0, vbNullString
                    
                    '~~> Get the handle of the "VBAProject - Project Properties" Window
                    xlAp.VBE.MainWindow.SetFocus
                    PropRet = FindWindow(vbNullString, MyProjName & " - Project Properties")
                    If PropRet <> 0 Then
                        '~~> Get the handle of the Button's "Window"
                        xlAp.VBE.MainWindow.SetFocus
                        ChildRet = FindWindowEx(PropRet, ByVal 0&, "Button", vbNullString)
            
                        '~~> Check if we found it or not
                        If ChildRet <> 0 Then
                            'MsgBox "Button's Window Found"
            
                            '~~> Get the caption of the child window
                            strBuff = String(GetWindowTextLength(ChildRet) + 1, Chr$(0))
                            GetWindowText ChildRet, strBuff, Len(strBuff)
                            ButCap = strBuff
            
                            '~~> Loop through all child windows
                            Do While ChildRet <> 0
                                '~~> Check if the caption has the word "OK"
                                If InStr(1, ButCap, "OK") Then
                                    '~~> If this is the button we are looking for then exit
                                    OpenRet = ChildRet
                                    Exit Do
                                End If
            
                                '~~> Get the handle of the next child window
                                xlAp.VBE.MainWindow.SetFocus
                                ChildRet = FindWindowEx(Ret, ChildRet, "Button", vbNullString)
                                '~~> Get the caption of the child window
                                strBuff = String(GetWindowTextLength(ChildRet) + 1, Chr$(0))
                                GetWindowText ChildRet, strBuff, Len(strBuff)
                                ButCap = strBuff
                            Loop
            
                            '~~> Check if we found it or not
                            If OpenRet <> 0 Then
                                '~~> Click the OK Button
                                SendMessage ChildRet, BM_CLICK, 0, vbNullString
                           Else
                                MsgBox "The Handle of OK Button was not found"
                            End If
                        Else
                             MsgBox "Button's Window Not Found"
                        End If
                    Else
                        MsgBox "The Handle of Properties window was not found"
                    End If
                Else
                    MsgBox "The Handle of OK Button was not found"
                End If
            Else
                 MsgBox "Button's Window Not Found"
            End If
        Else
            MsgBox "The Edit Box was not found"
        End If
    Else
        MsgBox "VBAProject Password Window was not Found"
    End If
    
    'Delete module
    DeleteModule oWb, MyModule
    
    'Clese workbook
    oWb.Close SaveChanges:=True
    
    'Close application
    xlAp.Quit
End Sub

Sub SendMess(Message As String, hWnd As Long)
    Call SendMessage(hWnd, WM_SETTEXT, False, ByVal Message)
End Sub

Sub DeleteModule(wb As Workbook, strVBMod As String)
        Dim VBProj As VBIDE.VBProject
        Dim VBComp As VBIDE.VBComponent
    
        Set VBProj = wb.VBProject
        Set VBComp = VBProj.VBComponents(strVBMod)
        VBProj.VBComponents.Remove VBComp
End Sub

...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39172801
скукотища
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
andreymxЕсли у кого есть идеи насчет чтения текстов запароленных макросов, прошу поделиться.
Пароль известен, ломать не надо! VBADecompiler . Не?
...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39173070
Фотография The_Prist
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
andreymxНе из vba - это как?Это на другом языке программирования. Не единым же VBA мир полнится :)
...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39173549
andreymx
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
The_PristandreymxНе из vba - это как?Это на другом языке программирования. Не единым же VBA мир полнится :)что же ты 5 раз на вопрос ответить не можешь
...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39173560
KL (XL)
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Насчет манипуляции самими компонентами VBE после распароливания, вот тут все нужные процедуры:

http://www.cpearson.com/Excel/VBE.aspx
...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39173561
Фотография The_Prist
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
andreymx,

Ты для начала задай вопрос корректно и нормально. И считать научись - где это ты меня 5 раз чего-то спрашивал? На вопрос "Не из VBA - это как" - получил ответ. На предыдущие тоже. Если не видишь связи между своими вопросами и моими на них ответами - то это не мои проблемы.
...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39173604
KL (XL)
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Вот доработанный код:

Код: vbnet
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
284.
285.
286.
287.
288.
289.
290.
291.
292.
293.
294.
295.
296.
297.
298.
299.
300.
301.
302.
303.
304.
305.
Option Explicit

'***************************************************************************************
'Author: KL(XL) 16-Feb-2016
'Based on the code published by Siddharth Rout in the below link
'http://www.siddharthrout.com/2013/04/24/unprotecting-vba-project-password-using-a-password-that-you-know/
'Requirements:
'Access to VBA Project Object Model must be trusted for this code to work
'You need to know the project password to be able to unprotect it by this code
'***************************************************************************************
'Win API declarations x86 x64
'***************************************************************************************
#If VBA7 Then
    Private Declare PtrSafe Function FindWindow Lib "user32" _
            Alias "FindWindowA" ( _
            ByVal lpClassName As String, _
            ByVal lpWindowName As String) As LongPtr
            
    Private Declare PtrSafe Function FindWindowEx Lib "user32" _
            Alias "FindWindowExA" ( _
            ByVal hWnd1 As LongPtr, _
            ByVal hWnd2 As LongPtr, _
            ByVal lpsz1 As String, _
            ByVal lpsz2 As String) As LongPtr
    
    Private Declare PtrSafe Function GetWindowText Lib "user32" _
            Alias "GetWindowTextA" ( _
            ByVal hwnd As LongPtr, _
            ByVal lpString As String, _
            ByVal cch As Long) As Long
    
    Private Declare PtrSafe Function GetWindowTextLength Lib "user32" _
            Alias "GetWindowTextLengthA" ( _
            ByVal hwnd As LongPtr) As Long
            
    Declare PtrSafe Function SendMessage Lib "user32" _
            Alias "SendMessageA" ( _
            ByVal hwnd As LongPtr, _
            ByVal wMsg As Long, _
            ByVal wParam As LongPtr, _
            lParam As Any) As LongPtr
            
    Dim Ret As LongPtr, ChildRet As LongPtr, OpenRet As LongPtr, PropRet As LongPtr
#Else
    Private Declare Function FindWindow Lib "user32" _
            Alias "FindWindowA" ( _
            ByVal lpClassName As String, _
            ByVal lpWindowName As String) As Long
    
    Private Declare Function FindWindowEx Lib "user32" _
            Alias "FindWindowExA" ( _
            ByVal hWnd1 As Long, _
            ByVal hWnd2 As Long, _
            ByVal lpsz1 As String, _
            ByVal lpsz2 As String) As Long
    
    Private Declare Function GetWindowText Lib "user32" _
            Alias "GetWindowTextA" ( _
            ByVal hwnd As Long, _
            ByVal lpString As String, _
            ByVal cch As Long) As Long
    
    Private Declare Function GetWindowTextLength Lib "user32" _
            Alias "GetWindowTextLengthA" ( _
            ByVal hwnd As Long) As Long
    
    Private Declare Function SendMessage Lib "user32" _
            Alias "SendMessageA" ( _
            ByVal hwnd As Long, _
            ByVal wMsg As Long, _
            ByVal wParam As Long, _
            lParam As Any) As Long
    
    Dim Ret As Long, ChildRet As Long, OpenRet As Long, PropRet As Long
#End If

Dim strBuff As String, ButCap As String

Const WM_SETTEXT = &HC
Const BM_CLICK = &HF5
'***************************************************************************************

Sub ManipulateProtectedVBAProject()
    Dim xlAp As Object, oWb As Object
    Dim VBComp As VBIDE.VBComponent
    Dim MyProjName As String
    Dim MyPassword As String
    Dim MyWbPath As String
    Dim MyModule As String
    Dim blnModuleDeleted As Boolean
    Dim UserResponse As VbMsgBoxResult
    Dim fd As FileDialog
    Dim i As Long, x As Long
    Dim strIniFolder As String
    
    'Provide name of module to delete
    MyModule = "Module1"
    'Provide password
    MyPassword = "test"
    'Get file path
    
    'Create log file
    x = FreeFile
    Open ThisWorkbook.Path & "\Log.txt" For Output As #x
    
    'Get files list via user dialog
    strIniFolder = ThisWorkbook.Path & "\"
    Set fd = Application.FileDialog(msoFileDialogOpen)
    With fd
        .Title = "Open Macro-Enabled Excel Files"
        .ButtonName = "Open"
        'Remove previous filters
        .Filters.Clear
        'Set file filters
        .Filters.Add _
                Description:="Microsoft Excel Files", _
                Extensions:="*.xlsm", _
                Position:=1
        .AllowMultiSelect = True
        'Starting folder
        .InitialFileName = strIniFolder
        .Show
        'Check if files selected
        If .SelectedItems.Count > 0 Then
            'Create a new instance of Excel application (guest)
            Set xlAp = CreateObject("Excel.Application")
            
            'Loop through selected files
            For i = 1 To .SelectedItems.Count
                
                'Open the workbook in guest application
                Set oWb = xlAp.Workbooks.Open(.SelectedItems.Item(i))
                'Get workbook's VBA Project Name
                MyProjName = oWb.VBProject.Name
                '***************************************************
                'Unprotection part
                '***************************************************
                'Check if VBA Project is protected
                If oWb.VBProject.Protection = vbext_pp_locked Then
                    'Make the application visible
                    xlAp.Visible = True
                    'Unlock VBA Project
                    UnlockVBA xlAp, MyProjName, MyPassword
                    'Update log
                    Print #x, Now(), oWb.Name, "Project [" & MyProjName & "] was temporarily unprotected"
                Else
                    'Update log
                    Print #x, Now(), oWb.Name, "Project [" & MyProjName & "] was not protected"
                End If
                '***************************************************
                'Main routine
                '***************************************************
                'Check if module exists
                On Error Resume Next
                Set VBComp = oWb.VBProject.VBComponents(MyModule)
                'If the module doesn't exist
                If Err <> 0 Then
                    'Update log
                    Print #x, Now(), oWb.Name, "Module [" & MyModule & "] not found"
                    'Do nothing, close workbook without saving
                    oWb.Close SaveChanges:=False
                'If the module exists
                Else
                    'Do the intended action. Delete module saving changes
                    oWb.VBProject.VBComponents.Remove VBComp
                    'Update log
                    Print #x, Now(), oWb.Name, "Module [" & MyModule & "] successfully deleted"
                    oWb.Close SaveChanges:=True
                End If
                On Error GoTo 0
                '***************************************************
            Next i
            'Close guest application
            xlAp.Quit
        Else
            'Update log
            Print #x, Now(), "Operation cancelled by the user: No files selected."
            'Feedback and exit if nothing selected
            MsgBox "No files selected"
        End If
    End With
    'Close log file
    Close #x
End Sub

Private Sub UnlockVBA(xlAp As Object, MyProjName As String, MyPassword As String)
    'KL: Activate remote VBE window to prevent losing control
    xlAp.VBE.MainWindow.SetFocus
    'Launch "VBA Project Password" window by clicking on VBA Project Properties button
    xlAp.VBE.CommandBars(1).FindControl(ID:=2578, recursive:=True).Execute
    'KL: Activate remote VBE window to prevent losing control
    xlAp.VBE.MainWindow.SetFocus
    'Get handle of "VBAProject Password" window
    Ret = FindWindow(vbNullString, MyProjName & " Password")

    'Check if we found it or not
    If Ret <> 0 Then
        'KL: Activate remote VBE window to prevent losing control
        xlAp.VBE.MainWindow.SetFocus
        'Get handle of TextBox window where we need to type password
        ChildRet = FindWindowEx(Ret, ByVal 0&, "Edit", vbNullString)
        'Check if we found Password Textbox
        If ChildRet <> 0 Then
            'Send password to TextBox
            SendMess MyPassword, ChildRet
            DoEvents
            'KL: Activate remote VBE window to prevent losing control
            xlAp.VBE.MainWindow.SetFocus
            'Get handle of Buttons window of "VBAProject Password" window
            ChildRet = FindWindowEx(Ret, ByVal 0&, "Button", vbNullString)
            'Check if we found Buttons window of "VBAProject Password" window
            If ChildRet <> 0 Then
                'Get caption of child window
                strBuff = String(GetWindowTextLength(ChildRet) + 1, Chr$(0))
                GetWindowText ChildRet, strBuff, Len(strBuff)
                ButCap = strBuff
                'Loop through all child windows
                Do While ChildRet <> 0
                    'Check if caption has word "OK"
                    If InStr(1, ButCap, "OK") Then
                        'If this is button we are looking for then exit
                        OpenRet = ChildRet
                        Exit Do
                    End If
                    'KL: Activate remote VBE window to prevent losing control
                    xlAp.VBE.MainWindow.SetFocus
                    'Get handle of next child window
                    ChildRet = FindWindowEx(Ret, ChildRet, "Button", vbNullString)
                    'Get caption of child window
                    strBuff = String(GetWindowTextLength(ChildRet) + 1, Chr$(0))
                    GetWindowText ChildRet, strBuff, Len(strBuff)
                    ButCap = strBuff
                Loop
                'Check if we found OK button of "VBAProject Password" window
                If OpenRet <> 0 Then
                    'Click OK Button. "VBAProject - Project Properties" window will open
                    SendMessage ChildRet, BM_CLICK, 0, vbNullString
                    'KL: Activate remote VBE window to prevent losing control
                    xlAp.VBE.MainWindow.SetFocus
    '***************************************************************************************
    'KL: Added this code to close "VBAProject - Project Properties" window
    '***************************************************************************************
                    'Get handle of "VBAProject - Project Properties" window
                    PropRet = FindWindow(vbNullString, MyProjName & " - Project Properties")
                    'Check if we found "VBAProject - Project Properties" window
                    If PropRet <> 0 Then
                        'KL: Activate remote VBE window to prevent losing control
                        xlAp.VBE.MainWindow.SetFocus
                        'Get handle of Buttons window of "VBAProject - Project Properties" window
                        ChildRet = FindWindowEx(PropRet, ByVal 0&, "Button", vbNullString)
                        'Check if we found buttons window of "VBAProject - Project Properties" window
                        If ChildRet <> 0 Then
                            'Get caption of child window
                            strBuff = String(GetWindowTextLength(ChildRet) + 1, Chr$(0))
                            GetWindowText ChildRet, strBuff, Len(strBuff)
                            ButCap = strBuff
                            'Loop through all child windows
                            Do While ChildRet <> 0
                                'Check if caption has word "OK"
                                If InStr(1, ButCap, "OK") Then
                                    'If this is button we are looking for then exit
                                    OpenRet = ChildRet
                                    Exit Do
                                End If
                                'KL: Activate remote VBE window to prevent losing control
                                xlAp.VBE.MainWindow.SetFocus
                                'Get handle of next child window
                                ChildRet = FindWindowEx(Ret, ChildRet, "Button", vbNullString)
                                'Get caption of child window
                                strBuff = String(GetWindowTextLength(ChildRet) + 1, Chr$(0))
                                GetWindowText ChildRet, strBuff, Len(strBuff)
                                ButCap = strBuff
                            Loop
                            'Check if we found OK button of "VBAProject - Project Properties" window
                            If OpenRet <> 0 Then
                                'Click OK Button to close "VBAProject - Project Properties" window
                                SendMessage ChildRet, BM_CLICK, 0, vbNullString
                            Else
                                MsgBox "Handle of OK Button of 'VBAProject - Project Properties' window Not Found"
                            End If
                        Else
                             MsgBox "Buttons window of 'VBAProject - Project Properties' Not Found"
                        End If
                    Else
                        MsgBox "Handle of 'VBAProject - Project Properties' window Not Found"
                    End If
    '***************************************************************************************
                Else
                    MsgBox "Handle of OK Button of 'VBAProject Password' window Not Found"
                End If
            Else
                 MsgBox "Buttons window of 'VBAProject Password' window Not Found"
            End If
        Else
            MsgBox "Edit Box of 'VBAProject Password' window Not Found"
        End If
    Else
        MsgBox "Handle of 'VBAProject Password' window was not Found"
    End If
End Sub

'Proc to click buttons or fill in textboxes found
Private Sub SendMess(Message As String, hwnd As Long)
    Call SendMessage(hwnd, WM_SETTEXT, False, ByVal Message)
End Sub

...
Рейтинг: 0 / 0
поиск в макросах в нескольких файлах
    #39173615
KL (XL)
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
На всякий случай прилагаю *.bas файл. В этом коде название VBA проекта теперь считывается автоматически. Единственный нерешенный вопрос - это язык интерфейса VBE: если он будет не английским, то нужно будет править все "капшоны" диалоговых окон, их текстбоксов и кнопок :)
...
Рейтинг: 0 / 0
21 сообщений из 21, страница 1 из 1
Форумы / Microsoft Office [игнор отключен] [закрыт для гостей] / поиск в макросах в нескольких файлах
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]