Pinaceous
Well-known Member
- Joined
- Jun 11, 2014
- Messages
- 1,124
- Office Version
- 365
- Platform
- Windows
Hi All,
I've recorded a macro to import an excel xlsx file known as
If the
My question is; how can I first run a sub to check if the
?
Here is my code that I'm playing around with that works fine unless the file is not available:
Any suggestions??
Many thanks!!
Pinaceous
I've recorded a macro to import an excel xlsx file known as
onto an open workbook's sheet.file1.xlsx
If the
is unavailable an error pops up:file1.xlsx
Please Enter Microsoft Access Database Engine OLD DB Initialization Information
My question is; how can I first run a sub to check if the
is present on the users desktop. For example:file1.xlsx
Code:
C:\Users\Desktop\file1.xlsx
Here is my code that I'm playing around with that works fine unless the file is not available:
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\file1.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\file1.xlsx"
.Refresh BackgroundQuery:=False
End With
Exit Sub
End Sub
Any suggestions??
Many thanks!!
Pinaceous