VBA, network name cannot be found - vba

The code I'm using is this, where myURL is a sharepoint folder,
objNet.MapNetworkDrive letter_drive, myURL
For some reason, this line of code usually works, the odd it fails with an error "network name cannot be found". Sometimes after failing, simply clicking run will carry on without an error.

Related

Debug.print statement causes a System.Configuration.ConfigurationErrorsException?

I am writing a VB.net application and in the form load I have a simple debug.print statement as per below:
Debug.Print("Application Started " & Format(Date.Now, "dd-MMM-yyyy hh:mm:ss tt"))
The application was running fine and I didn't have any errors but then I did something and I started getting an error. The last thing I did before noticing the error was I did a search and replace of a variable name start and I renamed this to startSearchIdx and I think it replaced text in my form1.designer.vbcode as I had to back out this change.
First this error only occurs on this current project. If I create a new VB.net windows form project with a button and this code then all is good, so it must be a setting or something in a configuration file which is causing the error?
When I run the application in debug mode, the application stops on the DEBUG.PRINT line as per the below image and I also receive the message:
A first chance exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Configuration.dll"
in the Immediate window. However if press F5 and continue then the application starts, and I see:
Application Started 16-Oct-2019 04:55:24 PM"
in the debug window.
The application then runs fine and any future debug.print statement appears to work in other code locations? I am hoping someone may be able to provide some light on this strange error?
Image of the VB IDE debug.print Configuration Error:

Unhandled win32 exception occured in the application

I have an application in vb.net that I'm testing out in Windows 10 and I seem to be getting an error (Images below). This app works flawlessly in Windows 7, and it actually works without any issues in Windows 10, the problem is, when I exit the application is when I get the error.
The way it's structured, is if I run it from IDE, i first see a Login Windows where user logs in and then goes to MENU. If it's run in our environment, user does not have to log in, so the log in form never appears, it goes directly to MENU.
Everything works great, until I go to EXIT Application, where it gets all messy, this is the code from EXIT button...
Dim Answer as Integer
Answer = MsgBox("Are you sure you wish to Close the application ?", MsgBoxStyle.YesNo)
If answer = vbYes Then
End
End If
These are the errors I get:
First I get this error, clicking on CLOSE PROGRAM closes it completely, if I click debug I get the below windows....
With the 2nd error it shows that I actually have VS2010 and VS2012, and it lets me debug. The issue is, the source code is in TFS, and it just so happens that I can't access the TFS from my windows 10 machine, (only from Win 7). So I can't debug it. But is there a reason why this is happening only in windows 10?
I even went as far as doing Me.Close() before END to make srue that the form is closed. And again, it works fine in Win 7, but win 10 it gives me the same problems.
Using "End" to close a program can be problematic; the comments and answer to this SO question explain why that is. As for the second issue that popped up once using Application.Exit(), that is a simple case of your program referencing multiple assemblies that have function calls with the same name. In this case, both the explicitly imported Microsoft.Office.Interop.Excel and implicitly imported System.Windows.Forms have "Application.Exit()" members. Since you have explicitly imported Excel, the compiler goes with that one when it's forced to decide which Exit() to use, which throws an error because of the context it's being used and doesn't actually close the program. To rectify that, all you have to do is explicitly tell the compiler which Exit() you want to use by replacing
Application.Exit()
with
System.Windows.Forms.Application.Exit()

VBA: An error occurred in the secure channel support

I have a code in VBA that worked perfectly for a long time. Suddenly it stopped working for no reason. Nothing has changed on my side.
I use it to download web pages and store them in strings like this:
Function something() As String
URL = "www..."
Set XMLHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
XMLHTTP.Open "GET", URL, False
XMLHTTP.send
something = XMLHTTP.responseText
End Function
at XMLHTTP.send I get the following error:
Run-time error '-2147012739 (80072f7d)': An error occurred in the secure channel support
Whats is the meaning of this error and what can be done?
I tried reading about it but it seems that its a generic error and could be many things. Perhaps Microsoft changed some protocols or something similar?
I had this same error:
6/30/2018
I'm running Excel on windows 7,
On a Mac, In Parallels.
This was a very simple fix.
Goto Control Panel,
Click Network and Internet,
Click Network and Sharing Center,
(at the Bottom Left CLICK Internet Options)
Internet Properties Dialog Box will come up,
Click the Advanced Tab
Scroll to bottom and turn on "Use TLS1.2"
(Mine was already Set Prior to receiving the Error)
Click Apply
Here is the link to the downloads need for the proper Windows OS Update file:
http://www.catalog.update.microsoft.com/search.aspx?q=kb3140245
I downloaded and Installed the UpDate from Windows Explorer (File Manager)
Restarted Windows
and ran the VBA.
It ran perfectly
Thanks to Srinath Gudimetla see his link is below for full details:
https://www.linkedin.com/pulse/working-vba-tls-protocol-srinath-gudimetla

QTP Error number -2147467259 when capturebitmap

This function used to work however now I see the message "General run error", and then:
msgbox Err.Number
The error number is **-2147467259**
The statement is like
Browser("Browser").Page("Page").Image("Image").CaptureBitmap "c:\temp\test.png",True
I don't recall anything changing and don't know what's causing the error.
Ok, I got the solution. Because now there is another screen connected to the computer. And Internet Explorer is launched on the second screen, not the principal one. So this statement cannot be well performed. I made IE opened in the principal screen, and problem sovled. But it's still strange that QTP can identify the webedits...

How do you run another .exe from VB.NET as another User?

How do you run another .exe from VB.NET but as another User?
I expect to launch a .exe like "Left Click -> Run As -> Enter User/Pass -> Click OK"
If I do that, my application runs as expected (I need to run it as another user to get access to some folders in the network)
But if I use this in VB.NET
System.Diagnostics.Process.Start(System.Windows.Forms.Application.ExecutablePath, PARAMETER, USER, PASSWORD, DOMAIN)
The application runs with the other user.. but Excel (inside my App with Interop) fails to open the file in the restricted folder.
(I run again the same app but with a different user, just to avoid creating more .exe files... but I already tried with vbScript)
Again, Process.Start FAILS to open excel using the other User... but Left Click -> Run as succedes at that... why?? another way??
this is what the app does:
Open the app
check if there's a parameter
if no parameter, then relaunch the application with the other user and send some parameter
if there is a parameter open excel
open a xlsx file
but if I double click... Excel opens... uses 50% CPU, and gives me the error that it can't open the file...
if I run it directly with the desired user and pass... everything executes fine
Any suggestions as how to solve this? (impersonate works fine.. but it opens Excel with the actual user.. not the one with rights)
Thanks!
If you get "Handle is invalid" error, you should try something like this:
dim info As New ProcessStartInfo("...")
info.UseShellExecute = False
info.RedirectStandardInput = True //This is the key
info.RedirectStandardError = True //This is the key
info.RedirectStandardOutput = True //This is the key
info.UserName = "username"
info.Password = "password"
Using (install As Process = Process.Start(info))
Dim output As String = install.StandardOutput.ReadToEnd()
install.WaitForExit()
End Using
Specifying any one of
RedirectStandardOutput=true, RedirectStandardError=true, or RedirectStandardInput=true
causes the process to be launched with STARTF_USESTDHANDLES. If your process does not have any of these handles, then CreateProcessWithLogon will fail with "Invalid Handle".
You MUST redirect it (even if you don't intend to write anything to it).
Regards
This is really interesting. By default, I believe the Excel COM components are set up to run as the Interactive User (ie the user logged into the box). If they are configured to run as the Launching User then impersonation should work. Of course, this does not explain why "Run As..." works (I don't know the mechanics of that so perhaps it's not impersonation).
One idea is to restructure the application to copy the files to a location Excel can access, manipulate them, and then copy the back.