VBA w/ Microsoft ACE OLEDB 12.0 connection strings

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,124
Office Version
  1. 365
Platform
  1. Windows
Hello Everyone,

I'm working with
Microsoft Office Professional Plus 2013
in using this code below that I've recorded to download a file know as
FileONE.xlsx
.

CODE1:
Code:
Sub Macro2()
'
    Sheets("Worksheet5").Select
     
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array( _
        "OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data Source=C:\Users\Desktop\FileONE.xlsx;Mode=Share Deny " _
        , _
        "Write;Extended Properties=""HDR=YES;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet " _
        , _
        "OLEDB:Engine Type=37;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;" _
        , _
        "Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy " _
        , _
        "Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False;" _
        , _
        "Jet OLEDB:Bypass UserInfo Validation=False;Jet OLEDB:Limited DB Caching=False;Jet OLEDB:Bypass ChoiceField Validation=False" _
        ), Destination:=Range("$A$1")).QueryTable
        .CommandType = xlCmdTable
        .CommandText = Array("'Inbound Flight$'")
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .SourceDataFile = "C:\Users\Desktop\FileONE"
        .Refresh BackgroundQuery:=False
    
    End With
    
    Exit Sub
End Sub

My question is I first want the sub to look for the file to see if it even exists; in simply using:

CODE2:
Code:
[COLOR=#ff0000]  If Dir("C:\Users\Desktop\fileONE.xlsx") = "" Then
       Msgbox "File does not Exist on the Desktop"
       Exit Sub
 End if[/COLOR]


In exploring this topic I've ran into https://www.connectionstrings.com/ace-oledb-12-0/ which is indicating to me that I need more to this CODE2 then meets the eye.

Can someone help me piece this information together, so I can make this CODE2 work for my application here??


Many thanks in advance!

R/
Pinaceous

PS. This is an extension from my previous asked thread http://Re: VBA *.xlsx file import; check to see if its there 1st which I found myself off topic. Or am I??
 
Last edited:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Why do you think you need something more?

The code you've posted should be sufficient for checking for the existence of the file.
 
Upvote 0
Hello,

When I use code2 as is, it does not for some reason work. Where I have to specifically add which user's (folder) into the code2 for it to work properly. Whereas in code1 I do not have to specify a specific user folder name there.

I'm assuming that I have to incorporate some of that OLEDG and password verberage that can be seen in code1.
 
Upvote 0
To check if a file exists all you need is the path to the file and its filename, you don't need any OLEDB stuff or passwords.
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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