I have in my VBA code connection string pointing to the workbook itself, e.g.:
"Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & ThisWorkbook.FullName & ";" & _
"Persist Security Info=False;" & _
"Extended Properties=""Excel 12.0 Macro;HDR=Yes"
It works well when the file is stored at local, but after it's uploaded to a Sharepoint space, it no longer works due to connection failure ("Connection could not be established!").
Any idea to get it working? Thanks in advance!
Not much detail here which leaves a lot of assumptions to be made...but here goes...
A bit of googling shows that there are lots of Microsoft.ACE.OLEDB errors with Access; you make not mention of Access so, that could be your issue right there - wrong connection type.
Since your connection is "to the workbook itself" the easy solution is to refernce the cells via a simple XL function.
In our environment, (Office 2007, SP 2007) it is worth noting that connections typically contain a connection string: "Provider=Microsoft.Office.List.OLEDB.2.0"). Again, probably the wrong connection string.
Try storing the spreadsheet in SP first, open the file (checked out of course), then create the connection.
If all else fails, I like the "record macro then fix the code" method!
Related
I have been asked to check at an issue on an "old" excel file, that have been moved to a new server and which is "no more working".
Before I was granted to access on the new server, I have tested on my laptop (Win10/office 64/oracle client 64/ODBC 64).
The VBA connection string is :
strConOracle = "Driver={Microsoft ODBC for Oracle}; CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
strConOracle = strConOracle & "(HOST=" & HOST & ")(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=" & DATABASE
strConOracle = strConOracle & "))); uid=" & USER & " ;pwd=" & PASSWORD & ";"
Set oConOracle = CreateObject("ADODB.Connection")
Set oRsOracle = CreateObject("ADODB.RecordSet")
After several tests, I think , I have understood that the string "{Microsoft ODBC for Oracle}" refers to an ODBC 32bits pilot. In my 64bits ODBC, the name is "Oracle in OraClient19Home1".
If I just change {Microsoft ODBC for Oracle} by {Oracle in OraClient19Home1} , it's not working (too quick to win :) )
So I'm just wondering If you know if ADODB connection is still possible on a 64 bits ?
And if there's some tricky thing we got to add in the VBA code.
Yes, I know there's a feature in excel called "getdata" that use external ODBC DSN connection, but it's too invasive. It needs to rework all the mechanism of the VBA code, and it's too long.
So I first want to check at VBA ADO connections.
Just for information , when I finally get in the issuing server (Windows ServerĀ® 2008 Standard/Office 32bits/Oracle 32bits/ODBC 32bits). I just need to add some trusted locations and buttons in FORM mode to get it work back again. I guess that's because in the ODBC 32bits, there is a pilot called "Microsoft ODBC for Oracle" or because there's a registry keys at this name :
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBCINST.INI\Microsoft ODBC for Oracle]
But I feel that, one day we won't be able to work in 32bits.
And it's may be a good warning for upgrading to 64bits.
regards
G
I have an Excel Macro Workbook (binary extension) that suddenly has developed 2 issues occasionally (sometimes it runs fine).
#1 Issue - Occasionally there is an error on Line 5
It appears the connection does not open. We get the error:
Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x7f8 Thread 0x1174 DBC
#2 Issue - Occasionally there is an error on Line 7
It appears the SQL can not run. It indicates the Worksheet tab can not be found even though it does exist. Note for this error we have no issue with Line 5 (Open Connection). The error that displays is:
[Microsoft][ODBC Excel Driver] The microsoft jet database engine could not find the object 'Worksheet Name'. Make sure the object exists...
For Issue #2 once we close the error dialog box and THE MACRO GETS DELETED !!!
Notes
The code module has not been changed in years Some days we get no errors/issues
This issue occurs for multiple Excel workbooks run by multiple people that run different VBA code blocks. However 1 of the code blocks is the same across all these macros which is the code snippet above.
The source data has not changed in years in terms of formatting or volume.
All these workbooks are on a Network server.
We are on Windows7/Excel 2010/ODBC Excel Driver (xls xlsx xlsm xlsb)
14.00.7180.5000
Code Snippet
1-Set adoConn = Nothing
2-Set adoRS = Nothing
3-Application.EnableCancelKey = xldisabled
4-strConn = "Driver={Microsoft Excel Driver (*.xls,*.xlsx,*.xlsm,*.xlsb)};DriverId=1046;Dbq=" & strFileName & ";IMEX=1;"
5-Set adoConn = New ADODB.Connection: adoConn.Open strConn
6-Application.EnableCancelKey = xlInterrupt
7-Set adoRS = New ADODB.Recordset:adoRS.Open Source:=strSQL,ActiveConnection:=adoConn
I'm curious as to why you're using ODBC to connect Excel to another Excel file, as opposed as to linking the data directly.
Intermittent connection problems point to a network issue. I would suggest removing and re-creating the ODBC connection, but I'd first want to confirm the value of strFileName as referred to in the connection string. Is it an actual server on your internal network, or an external source? (ie, is it a UNC path?)
An intermittent Unable to open registry key error likely sounds worse than it is; when having connection problems, Windows & Excel will easily get confused as to what the real problem is.
It sounds like your setup has been in place, possibly un-maintained, for a long time. When is the last time the client and server were rebooted? (Should be nightly.) Defrag, disk cleanup, etc?
As for the issue of the macro "getting deleted" when you close an error dialog, I'd need to see proof of that. I think you're misunderstanding something, unless you're re-writing the macro from scratch each time this happens..
I am facing "Unspecified error" in only one PC of my users.
Run-time error '-2147467259 (80004005)':
Unspecified error
I am running the below VBA code to open a connection to Access database located in network shared drive. But the code throws the error whenever it is trying to run the .Open statement.
I thought it is a driver issue and installed Access 2007 Database engine in the user's PC and replaced Provider with "Microsoft.ACE.OLEDB.12.0" but it doesn't work.
Code:
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim retVal As Boolean
Dim strSQL As String
retVal = False
On Error GoTo CatchError
Set cn = New ADODB.Connection
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Jet OLEDB:Database Password") = Initialize.GetDBPwd 'returns pass
.Open Initialize.GetDbConnectionString 'returns the network DB path
End With
I have the same issue while making an ADODB connection from a local Excel file to another local Excel file.
The only way how I solve it is re-opening the main Excel file from which I do the connection. Nothing else done, and the function works again.
My connection function:
Sub SetConReadOnly(ByRef con1 As Object, ByRef rst1 As Object, sFile As String)
If con1 Is Nothing Then Set con1 = CreateObject("ADODB.Connection")
If rst1 Is Nothing Then Set rst1 = CreateObject("ADODB.Recordset")
con1.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & sFile & ";" & _
"Extended Properties=""Excel 12.0;HDR=No;IMEX=1;"""
End Sub
(I use Office 2013 32-bit, Windows 7 64-bit)
What is the version of your Excel?
I had that error, and the solution was changing the provider. Try changing to this:
On Error GoTo CatchError
Set cn = New ADODB.Connection
With cn
.provider = "Microsoft.Mashup.OleDb.1"
.Properties("Jet OLEDB:Database Password") = Initialize.GetDBPwd 'returns pass
.Open Initialize.GetDbConnectionString 'returns the network DB path
End With
Still haven't found any solution to this issue but it seem the issue is limited to only one user.
I wrote some test macros, in the same file which has the original macros, that open DB connection to local DB file and remote DB file. The test is successful but for some reason that one particular macro still throws that "Unspecified Error" in that specific users machine.
We concluded it is most likely due to a office got corrupted. We will repair the office and hopefully that should fix the issue. Will let you know if this works.
Thanks.
I have faced this issue and identified that this issue is specific to a Win7 64 Bit with a 32 Bit Office Installation. The solution I accidentally came across was that If I saved the file manually and rerun the code, it worked seamlessly post that. On trying to incorporate a save in the error handler and calling in the main function again did not work. However saving the file through Application.SendKeys "^s" and then running the file through another thread could replicate the outcome of the manual save.
On further investigation, I identified that the error was because of certain columns in the source being added at run-time before the query and it seems the sql engine queries from a different internal raw source which is not updated with the changes unless the save happens and that was the reason for error.
I got this error while using same variables in two different modules. It went away when I changed the variable names. It is strange but it worked!! Hope that solves your problem. Thanks
I am currently getting the following error:
Microsoft OLE DB Service Components error '80040e73'
Format of the initialization string does not conform to the OLE DB specification.
My code is as follows with the variable ExportPath being created on the fly to create unique XLS names. e.g. D:\RiskCheck\Website\demo\newsite\exports\Reporting_Export_NTQ0KZZU0T262014115941.xls
set cnn=Server.CreateObject("ADODB.Connection")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source="&ExportPath&";" & _
"Extended Properties='Excel 8.0;HDR=YES;';"
This issue has been driving me absolutely mental all morning and numerous fixes found across Google haven't been successful, any advice rather welcome!
Im building a program in Excel VBA to automate a process and I require data stored in a csv file to be imported. So, I'm trying to use a query table to import specific columns in a csv file.
Im using ADO to interface with the csv file using the Jet Provider OLE DB. In the connection string I have specified the provider, data source, and extended properties. Im using windows xp and office 2003, so my Excel version is 8.0. I specified the provider as Microsoft.Jet.OLEDB.4.0. My code is pasted below. When the code executes I get the error "Could not find installable ISAM" at the last line that I included in the below code. I cant find anything wrong with the syntax so I was wondering if this error could be because I dont have the correct version of Jet installed? Please see code below. Thanks
Sub Excel_QueryTable()
Dim oCn As ADODB.Connection
Dim oRS As ADODB.Recordset
Dim ConnString As String
Dim SQL As String
Dim qt As QueryTable
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\testfile.csv;" & _
"Extended Properties=Excel 8.0;HDR=Yes; FMT=Delimited; IMEX=1"","
Set oCn = New ADODB.Connection
oCn.ConnectionString = ConnString
oCn.Open
Try this:
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\directory\where\csv\file\is\;" & _
"Extended Properties=""text;HDR=Yes;FMT=Delimited"""
I don't think you want to use the "Excel 8.0" portion, but you aren't actually connecting to an Excel worksheet; you're connecting to a text file. Also, you had extra spaces, and connection strings are REALLY picky about those, so I've deleted them.
Note that you can set the delimiter here:
HKLM\SOFTWARE\Microsoft\Jet\4.0\Engines\Text\Format
Mine is currently CSVDelimited; other options are TabDelimited and Delimited(;)
I found this info at: http://www.connectionstrings.com/textfile
-- EDIT --
Instead of pointing to a specific .csv file, you actually point the data source to a target directory. Note my changes above, in the connection string: the filename has been removed, and the path now ends in a \.
In order to use this type of data source, you actually need to teach the driver how the file is laid out. You do this through the use of a schema.ini file.
You can create the .ini file one of two ways:
Manually edit the file by hand, in notepad, using the above link to provide usage.
Use the tool built into the ODBC Data Source Admin.
In order to use the tool, you need to actually go through the steps of creating a data source. You don't actually need the data source, but as far as I can tell, it's the only way to get to the create schema.ini creation tool.
To get there:
Go to the ODBC control panel.
Add a new DSN, type: Microsoft Text Driver (*.txt, *.csv), click Finish
On "ODBC Text Setup", uncheck Use Current Directory and select the directory where your file lives.
Click on the options button, and click on the Define Format button.
Click on the file that you want to work with, and click "Guess" to get you started, then refine the data types as necessary.
When done, click OK, and you should see a schema.ini file in the directory where your .csv file is. Open it in notepad, and make sure it looks right.
The above connection string should now work correctly, using ONLY the directory where your csv lives, not the full path to the .csv.