I have a weird problem with an excel VBA application.
It uses a web service to connect to a mysql database.
it all runs well in most computers....however in some computers it throws an error:
ERROR WHEN COMPILING "METHOD OR DATAOBJECT NOT FOUND"
All computers are running Windows 7 and Office 2007.
Here is an example of the web service code (where the error happens)
Public Function wsm_get_portscountries(ByVal str_SQLQuery As String) As MSXML2.IXMLDOMNodeList
On Error GoTo wsm_get_portscountriesTrap
Set wsm_get_portscountries = sc_WebService1.wsm_get_portscountries(str_SQLQuery)
Exit Function
wsm_get_portscountriesTrap:
WebService1ErrorHandler "wsm_get_portscountries"
End Function
The error highlights the bolded part here:
sc_WebService1.wsm_get_portscountries(str_SQLQuery)
Has anyone encountered the same problem ?? Any ideas ??
As I said, on most computers it runs well, no problems, it only happens with some.
Thanks in advance.
additional information:
class module
Private Sub Class_Initialize()
On Error GoTo Class_Initialize_error
Dim str_WSML As String
str_WSML = ""
Set sc_WebService1 = New SoapClient30
sc_WebService1.MSSoapInit2 c_WSDL_URL, str_WSML, c_SERVICE, c_PORT, c_SERVICE_NAMESPACE
sc_WebService1.ConnectorProperty("ProxyServer") = "<CURRENT_USER>"
sc_WebService1.ConnectorProperty("EnableAutoProxy") = True
Exit Sub
Class_Initialize_error:
End Sub
Related
I use VBA to automate an external application that recently changed their COM API. The new API loads files asynchronously (used to be synchronous) so I need to wait for the file loaded trigger before I continue when I try to load a file.
I have tried the methods listed on the Microsoft website (EX1, EX2) which were also part of an accepted answer on StackOverflow.
Below is the code I have in a class module named UCExternal to contain the external application object:
Public WithEvents obj As External.Application
Private fileLoaded As Boolean
Private Sub obj_OnFileLoaded(ByVal lLayer As Long, ByVal strUNCPath As String)
Debug.Print lLayer
Debug.Print strUNCPath
fileLoaded = True
End Sub
Public Sub LoadSingleFile(fileStr As String)
fileLoaded = False
obj.LoadFile 0, fileStr
Do
DoEvents
Loop Until fileLoaded
End Sub
And then this is what I had in a normal code module to run using a button on the sheet:
Sub TryLoadFile()
Dim extObj as New UCExternal
set extObj.obj = CreateObject("External.Application")
filePath = "path/to/file"
extObj.LoadSingleFile filePath
End Sub
The event code never seems to fire and instead the Do Loop just runs until Excel crashes. I don't know if there is a way to confirm the application actually sent the event trigger? I have read through the new documentation for the application and that is the event they say to wait for. I have reached out to them for help as well but I wasn't sure if there was something more general I may have been missing. I have not worked with events external to Excel in the past. If I just step through it using the debugger and manually exit the Do Loop eventually the rest of the code that works on the loaded file works as well, so it does load the file.
extObj needs to be declared outside of TryLoadFile, or it will go out of scope and get cleared as soon as TryLoadFile completes
Dim extObj as New UCExternal
Sub TryLoadFile()
Set extObj = New UCExternal
set extObj.obj = CreateObject("External.Application")
filePath = "path/to/file"
extObj.LoadSingleFile filePath
End Sub
I have this code:
Public channel As Long
Sub Button1_Click()
MsgBox "all is OK"
' Application.ActiveCell.Font.Bold = True
channel = Application.DDEInitiate("Excel", "System")
MsgBox "Conversation started"
End Sub
Why DDEInitiate expression gives error 13?
The registry keys shown in the office-watch blog mentioned by #VincentG were only relevant for Writer. Excel has its own set of keys (which one can check using Sysinternals ProcMon, both when Excel starts, and when DDEInitiate is called from VBA), which are at least:
In HKCU\SOFTWARE\Microsoft\Office\16.0\Excel\Options - DDEAllowed:REG_DWORD=1
In HKCU\SOFTWARE\Microsoft\Office\16.0\Excel\Security - DisableDDEServerLaunch:REG_DWORD=0, DisableDDEServerLookup:REG_DWORD=0.
I didn't check which of them are the minimum requirement. Anyway, indeed, enabling DDE would be a security risk.
This is more of general question, I suppose, as-well-as help with a specific line of code.
I have an Excel file that I was working on just a few days ago that was working fine, however now whenever I try to run the macro in the workbook to pull data from a website, I receive the error "Run-time error '380': A script engine for the specified language can not be created."
Here is the code block where I am running into the issue. I have starred the specific section where the error is thrown.
Dim H As Object, S As Object, jParse As Object, X64 As Object, i&
Set H = CreateObject("WinHTTP.WinHTTPRequest.5.1")
H.SetAutoLogonPolicy 0
#If Win64 Then
Set X64 = x64Solution()
X64.execScript "Function CreateObjectx86(sProgID) Set CreateObjectx86 = CreateObject(sProgID): End Function", "VBScript"
Set S = X64.CreateObjectx86("MSScriptControl.ScriptControl")
#Else
Set S = CreateObject("ScriptControl")
#End If
***S.Language = "JScript"***
S.AddCode "function keys(O) { var k = new Array(); for (var x in O) { k.push(x); } return k; } "
I have never seen this error before and I am not sure how to fix this issue. I have looked online and have thus far been unsuccessful in figuring out the problem. I have also tried downloading and installing the zip file from Microsoft in this link: https://gallery.technet.microsoft.com/scriptcenter/Registry-key-to-re-enable-835fba77 with no success.
Any help would be appreciated, because I really don't know what to do here.
Also if Stack Overflow is not really the place for this kind of question, any help in directing me somewhere that would be better suited for this kind of problem would be appreciated.
I just had a similar encounter attempting to use JScript to parse some JSON from the SO API using a x64 machine.
Disclaimer: I did not author the following procedures, but unfortunately I do not have the source of where I obtained them either.
As you've probably already figured out, MSScriptControl.ScriptControl doesn't like the x64 architecture very well. Here are a couple of functions that will allow you to do what you need.
I placed these in a separate module:
Public Function CreateObjectx86(Optional sProgID, Optional bClose = False)
Static oWnd As Object
Dim bRunning As Boolean
#If Win64 Then
bRunning = InStr(TypeName(oWnd), "HTMLWindow") > 0
If bClose Then
If bRunning Then oWnd.Close
Exit Function
End If
If Not bRunning Then
Set oWnd = CreateWindow()
oWnd.execScript "Function CreateObjectx86(sProgID): Set CreateObjectx86 = CreateObject(sProgID): End Function", "VBScript"
End If
Set CreateObjectx86 = oWnd.CreateObjectx86(sProgID)
#Else
Set CreateObjectx86 = CreateObject(sProgID)
#End If
End Function
Private Function CreateWindow()
Dim sSignature, oShellWnd, oProc
On Error Resume Next
sSignature = Left(CreateObject("Scriptlet.TypeLib").GUID, 38)
CreateObject("WScript.Shell").Run "%systemroot%\syswow64\mshta.exe about:""about:<head><script>moveTo(-32000,-32000);document.title='x86Host'</script><hta:application showintaskbar=no /><object id='shell' classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'><param name=RegisterAsBrowser value=1></object><script>shell.putproperty('" & sSignature & "',document.parentWindow);</script></head>""", 0, False
Do
For Each oShellWnd In CreateObject("Shell.Application").Windows
Set CreateWindow = oShellWnd.GetProperty(sSignature)
If Err.Number = 0 Then Exit Function
Err.Clear
Next
Loop
End Function
Then you can go back to your S object and set it this way:
Dim S As Object
Set S = CreateObjectx86("MSScriptControl.ScriptControl")
S.Language = "JScript"
This seems like it should be an easy one but I'm stuck.
I'm running a VBA script in Access that creates a 40+ page report in Excel.
I am creating an Excel Application Object using Early Binding:
Public obj_xl As New Excel.Application
Here is an example of how I am referencing the object:
With obj_xl
.Workbooks.Add
.Visible = True
.Sheets.Add
.blahblahblah
End With
The problem is that the procedure has become too large and I need to break the code up into separate modules.
If I try to reference the Excel Application Object from a different module than it was created in, it throws an error ("Ambiguous Name").
I'm sure I could do something with Win API but that seems like it would be overkill.
Any thoughts? Thanks
this is the type of situation that can cause the error "Ambiguous Name"
Function Split(s As String)
MsgBox s
End Function
Function Split(s As String)
MsgBox s
End Function
I know the example is trivial, but what you are looking for is a function , an object and/or a form control with the same names.
If you convert your declaration to Global, you can reference it in all your modules. For example, in one module, put this at the top:
Global obj_xl As Excel.Application
Then in an another module,
Sub xx()
Set obj_xl = New Excel.Application
Debug.Print obj_xl.Name
End Sub
I am maintaining an application that was written in Visual Basic 6.0 and makes use of the several OLE controls with Excel.Sheet.8 class objects. Several users are getting the following error when they reach a point in code that attempts to manipulate the excel objects.
Run-time error '91': Object variable or With block variable not set
Below are examples of the code that trigger this error. I believe that the issue happens at:
Set oExcel = oleXl.object
Here are the points in the code where it happens:
Private Sub Form_Load()
Dim i As Integer
Dim j As Integer
Dim sTempStringA As String
Dim sTempStringB As String
'Set up excel sheet
centerform Me
Set oOutGrid = oleXlOutput.object
...
Private Sub Form_Load()
centerform Me
Set oOtherFx = oleXlFx.object
...
Private Sub Form_Load()
Dim iRet As Integer
Dim i As Integer
On Error GoTo Err_Handler
centerform Me
Call InitArray
Me.Caption = "TJUJ | Version " & version & " | Enter Custom Fx"
Set oBook = oleExcel.object
...
Is there a specific situation or environment in which this error would be generated from this line of code OR a way that I can ensure the object will always be accessible at this point in the code?
The error only happens occasionally, and I can't reproduce it on my developer machine at all. I also do not have access to the machines that it is happening on, but it seems to be encountered when there is an instance of the EXCEL.EXE process running.
When you get runtime-error 91, you can bet there's an uninitialized object somewhere in the statement. In other words, you are trying to use the properties or methods of a variable/object with a value of Nothing.
In your examples, oleXl, oleXlFx, and oleExcel are probably Nothing. So when you refer to their .object property, you trigger the RTE.
Somewhere in your code these variables have to be initialized to something. Look for statements like Set oleXl = CreateObject("Excel.Application") or Set oleXl = New Excel.Application
One suggestion; when you find the statements that actually initialize those OLE objects, check to see how the error-handling is coded. If you see things like this:
On Error Resume Next
Set oleXl = CreateObject(...
add a test to make sure the object was instantiated
On Error Resume Next
Set oleXl = CreateObject(...
If oleXl Is Nothing Then
MsgBox "Hey, my object is Nothing!"
End If
Microsoft suggests that we can fix error 91 by creating a new registry key. To create a new key follow the steps below.
Click on the Windows Start menu
Type Regedit in the search box
Press Enter
Locate the following entry in the registry. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Transaction Server
Now select the transaction server and right click on it
Select New and then choose Key
Name the key as Debug
Right click on the Debug key and choose New
Now select Key and name the key as RunWithoutContext
Ref: http://backspacetab.com/error-91/