Good day, dear gurus! There is a certain base of logins (cell H) and passwords (cell I) in Excel. Periodically, I have to check them for performance.

To do this, create a "Network Connection" using the "Network Connection Wizard" in which the items -> "Connect to the Internet" have been selected. This connection is called test .

I work on this principle ... 1. I copy the username, I minimize Excel 2. I call the network connection test, I insert the username. 3. I expand Excel I copy the password I minimize Excel 4. I expand the network connection test I insert the password I press the connect button and I see whether the authorization has passed.

Is it possible to automate these operations using macro VBA? (I will break the network connection manually) On the Internet, no one seems to have set such a task, and I think many will be interested. I started to understand macros not long ago and I do not have much experience. Thank you for attention!

    2 answers 2

    And you are only interested in solving the problem within VBA?

    Yes, this is quite possible to crank on VBA, but for this you need to find the necessary WinApi functions. There are search functions for windows and components, as well as having to tinker with UISpy to see the component tree on the windows.

    I found an example only for C #, but the main point should be clear and can be sawed under VBA:

    int hwnd=0; IntPtr hwndChild=IntPtr.Zero; //Get a handle for the Calculator Application main window hwnd=FindWindow(null,"Calculator"); if(hwnd == 0) { if(MessageBox.Show("Couldn't find the calculator" + " application. Do you want to start it?", "TestWinAPI", MessageBoxButtons.YesNo)== DialogResult.Yes) { System.Diagnostics.Process.Start("Calc"); } } else { //Get a handle for the "1" button hwndChild = FindWindowEx((IntPtr)hwnd,IntPtr.Zero,"Button","1"); //send BN_CLICKED message SendMessage((int)hwndChild,BN_CLICKED,0,IntPtr.Zero); //Get a handle for the "+" button hwndChild = FindWindowEx((IntPtr)hwnd,IntPtr.Zero,"Button","+"); //send BN_CLICKED message SendMessage((int)hwndChild,BN_CLICKED,0,IntPtr.Zero); //Get a handle for the "2" button hwndChild = FindWindowEx((IntPtr)hwnd,IntPtr.Zero,"Button","2"); //send BN_CLICKED message SendMessage((int)hwndChild,BN_CLICKED,0,IntPtr.Zero); //Get a handle for the "=" button hwndChild = FindWindowEx((IntPtr)hwnd,IntPtr.Zero,"Button","="); //send BN_CLICKED message SendMessage((int)hwndChild,BN_CLICKED,0,IntPtr.Zero); } 

    You can use .NET, there is a special space that can get rid of the fuss with WinApi.

    Perhaps there is a ready-made software that can help you in this matter.

    I also do not exclude that in WinApi you may need a function to check the Internet connection and you don’t have to interact with the window with pens.

    • Your example is good, but I do not speak well C # I have a network with C # but only the most basic level ... ((But thanks for the answer anyway. I’m interested in VBA because the database is in excel and I don’t see a new database on delphi of expediency. - p_redator

    In general, everything turned out to be easier than I thought :) There is a rasdial utility that can launch a network connection. It remains only to transfer the login and password values ​​to it. In general, the code looks like this

     rasdial Test login pass 

    Where:

     Test - имя заранее созданного сетевого подключения PPPoE login - логин пользователя pass - пароль пользователя 

    Well, in my case it looks like this:

     Sub test() Shell "rasdial Test " + CStr(Cells(ActiveCell.Row, 7).Value) + " " + CStr(Cells(ActiveCell.Row, 8).Value), vbNormalFocus End Sub 

    Thank you all for your activity. I think in the future, this topic will need someone else