What is the wrong with my code? (Open Connection To Excel From Access ADO)

MNpoker

Board Regular
Joined
Dec 15, 2003
Messages
154
Very frustrated. I have set this up already in Excel to go to Access but it seems like when I ask questions here I get told to do things in Access but nothing seems to work!

I want to open an Excel File then Save that Excel file under a new name.
From there I want to export (I'm now working in Access) data to the new Excel workbook.

I am getting nowhere :(

This gives me a 'unrecognizable database' format error.

Is this worth my time? I am not a programmer by trade and if this requires one to be a programmer I have to go back to Excel.

(It seems I have to specify something somewhere but I can not find any exmples - tons exist for programming in Excel)

Private Sub cmdOpenExcelTemplate_Click()

Dim strFullPath As String
Dim sXL_Path As String
Dim XL As Excel.Application
Dim Excel As Excel.Workbook

Dim Objcat As New ADOX.Catalog
Dim oXLConn As New ADODB.Connection

' Get the Path Name
strFullPath = CurrentDb().Name

sXL_Path = Left(strFullPath, InStrRev(strFullPath, "\")) & TargetXLFile

MsgBox (sXL_Path)



With oXLConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = sXL_Path
.Open
End With

oXLConn.Close
Set Objcat = Nothing
Set oXLConn = Nothing
End Sub
-----------------------------------------

I can get it to open the Excel file (not using ADO) but not open and connect to it.
 
Last edited:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,214,648
Messages
6,120,725
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top